//====================================================================== //Battleship //Copyright (C) 2004 Jake Poznanski (jake@ti-news.net) // //This program is free software; you can redistribute it and/or //modify it under the terms of the GNU General Public License //as published by the Free Software Foundation; either version 2 //of the License, or (at your option) any later version. // //This program is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. // //You should have received a copy of the GNU General Public License //along with this program; if not, write to the Free Software //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //====================================================================== // Returns number of elements #define dim(x) (sizeof(x) / sizeof(x[0])) //---------------------------------------------------------------------- // Generic defines and data types // struct decodeUINT { // Structure associates UINT Code; // messages // with a function. LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM); }; struct decodeCMD { // Structure associates UINT Code; // menu IDs with a LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function. }; //---------------------------------------------------------------------- // Generic defines used by application #define ID_ACCEL 1 // Accelerator table ID #define ID_ICON 3 //Menu Defines #define ID_TOOLBAR1 100 //Toolbar #define ID_MENU 101 //Menu #define ID_FILE 102 //File Popup //Menu Command Functions #define IDM_EXIT 200 #define IDM_ABOUT 201 // String table IDs #define IDS_FILE 300 #define IDS_EXIT 301 #define IDS_ABOUT 302 #define SHMENUBAR RCDATA #define I_IMAGENONE (-2) //Program defines #define GAME_PROGRESS 1 #define GAME_LOST 2 #define GAME_WIN 3 #define MAXMISS 25 //Globals int Board[8][8]; int Ships[4][2]; int ShipCount = 0; //Set to zero for now int MissesLeft = MAXMISS; int GameStatus = GAME_PROGRESS; bool SoundEnabled = true; //---------------------------------------------------------------------- // Function prototypes // HWND InitInstance (HINSTANCE, LPWSTR, int); int TermInstance (HINSTANCE, int); HWND MyCreateMenuBar (HWND hWnd, int idToolbar); void InitBoard(); void AddShip( int length ); // Window procedures LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM); // Message handlers LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoSizeMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoNotifyMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoCommandMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoSettingChangeMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoActivateMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoPaintMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoLButtonUpMain (HWND, UINT, WPARAM, LPARAM); // WM_COMMAND message handlers LPARAM DoMainCommandExit (HWND, WORD, HWND, WORD); LPARAM DoMainCommandAbout (HWND, WORD, HWND, WORD); LPARAM DoMainCommandNewGame (HWND, WORD, HWND, WORD); LPARAM DoMainCommandHelp (HWND, WORD, HWND, WORD); LPARAM DoMainCommandOptions (HWND, WORD, HWND, WORD); //Dialog Box Proc BOOL CALLBACK HelpDlgProc( HWND, UINT, WPARAM, LPARAM ); BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM ); BOOL CALLBACK OptionsDlgProc( HWND, UINT, WPARAM, LPARAM );