int main() { while (true) { //initialize Randomize(); Set<string> wordsSeen; Lexicon lex("lexicon.dat"); Grid<string> board(4,4); //changes for 5x5 SetWindowSize(9, 5); InitGraphics(); DrawBoard(4,4); //changes for 5x5 Welcome(); GiveInstructions(); //either set up the board automatically or let the user set it up cout << "Would you like to configure the board? "; string response = GetLine(); response = ConvertToUpperCase(response); if (response == "YES") { UserConfigureBoard(board); } else { InitializeBoard(board); } //have the player play, then the computer PlayerTurn(board, lex, wordsSeen); ComputerTurn(board, lex, wordsSeen); //check if the user wants to play again cout << "Would you like to play again? "; response = GetLine(); response = ConvertToUpperCase(response); if (response != "YES") break; } return 0; }
void Game() { check = false; FreeTree(tree); if (NULL != buttonsBoard){ FreeButtonsBoard(); } if (-1 == EventHandler_init(&Quit, &error_global)) { guiQuit = -1; return; } chosenMove = NULL; gameSelectedSquare_control = NULL; showDepthOptions = false; get_moves_for_color(board, curSettings->next_turn, &curMovesList); CheckGameOver(); control* window; if (-1 == Create_window(GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &window, &error_global)) { guiQuit = -1; return; } if (-1 == CreateTree(window, &tree, &error_global)) { FreeControl(window); guiQuit = -1; return; } control* gameBoarBackground_control; if (-1 == Create_panel_from_bmp( GAMEBOARDBACKGROUNDFILENAME, GAMEBOARDBACKGROUNDNAME, 0, 0, (Uint16)GAMEBOARDBACKGROUND_W, (Uint16)GAMEBOARDBACKGROUND_H, &gameBoarBackground_control, &error_global)) { guiQuit = -1; return; } UINode* gameBoarBackground_node; if (-1 == CreateAndAddNodeToTree(gameBoarBackground_control, tree, &gameBoarBackground_node, &error_global)) { FreeControl(gameBoarBackground_control); guiQuit = -1; return; } if (-1 == buildBoardUITree(&error_global)) { guiQuit = -1; return; } Sint16 quitButton_x_location = (Sint16)(GAMEBOARDBACKGROUND_W - BUTTON_W - 0.5 * MARGIN); Sint16 quitButton_y_location = (Sint16)(GAMEBOARDBACKGROUND_H - BUTTON_H - 1.5 * MARGIN); control* quitButton_control; if (-1 == Create_Button_from_bmp( BUTTONQUITFILENAME, BUTTONQUITFILENAME, BUTTONQUITNAME, quitButton_x_location, quitButton_y_location, (Uint16)BUTTON_W, (Uint16)BUTTON_H, &Quit_ButtonClick, &quitButton_control, &error_global)) { guiQuit = -1; return; } UINode* quitButton_node; if (-1 == CreateAndAddNodeToTree(quitButton_control, gameBoarBackground_node, &quitButton_node, &error_global)) { FreeControl(quitButton_control); guiQuit = -1; return; } if (-1 == AddToListeners(quitButton_control, &error_global)) { FreeControl(quitButton_control); guiQuit = -1; return; } Sint16 bestButton_x_location = quitButton_x_location; Sint16 bestButton_y_location = (Sint16)(quitButton_y_location - BUTTON_H - 1.5 * MARGIN); control* bestButton_control; if (-1 == Create_Button_from_bmp_transHighlight( BUTTONBESTMOVEFILENAME, BUTTONTRANSPARENTHIGHLIGHTEDFILENAME, BUTTONBESTMOVENAME, bestButton_x_location, bestButton_y_location, (Uint16)BUTTON_W, (Uint16)BUTTON_H, &GameBoardBest_ButtonClick, &bestButton_control, &error_global)) { guiQuit = -1; return; } UINode* bestButton_node; if (-1 == CreateAndAddNodeToTree(bestButton_control, gameBoarBackground_node, &bestButton_node, &error_global)) { FreeControl(bestButton_control); guiQuit = -1; return; } if (-1 == AddToListeners(bestButton_control, &error_global)) { guiQuit = -1; return; } int saveButton_x_location = quitButton_x_location; int saveButton_y_location = 2 * MARGIN; control* saveButton_control; if (-1 == Create_Button_from_bmp_transHighlight( BUTTONSAVEFILENAME, BUTTONTRANSPARENTHIGHLIGHTEDFILENAME, BUTTONSAVENAME, saveButton_x_location, saveButton_y_location, (Uint16)BUTTON_W, (Uint16)BUTTON_H, &GameBoardSave_ButtonClick, &saveButton_control, &error_global)) { guiQuit = -1; return; } UINode* saveButton_node; if (-1 == CreateAndAddNodeToTree(saveButton_control, gameBoarBackground_node, &saveButton_node, &error_global)) { FreeControl(saveButton_control); guiQuit = -1; return; } if (-1 == AddToListeners(saveButton_control, &error_global)) { guiQuit = -1; return; } Sint16 mainMenuButton_x_location = (Sint16)(quitButton_x_location); Sint16 mainMenuButton_y_location = (Sint16)(saveButton_y_location + BUTTON_H + 1.5 *MARGIN); control* mainMenuButton_control; if (-1 == Create_Button_from_bmp_transHighlight( BUTTONMAINMENUFILENAME, BUTTONTRANSPARENTHIGHLIGHTEDFILENAME, BUTTONMAINMENUNAME, mainMenuButton_x_location, mainMenuButton_y_location, (Uint16)BUTTON_W, (Uint16)BUTTON_H, &GameBoardMainMenu_ButtonClick, &mainMenuButton_control, &error_global)) { guiQuit = -1; return; } UINode* mainMenuButton_node; if (-1 == CreateAndAddNodeToTree(mainMenuButton_control, gameBoarBackground_node, &mainMenuButton_node, &error_global)) { FreeControl(mainMenuButton_control); guiQuit = -1; return; } if (-1 == AddToListeners(mainMenuButton_control, &error_global)) { guiQuit = -1; return; } if (check) { char* filename = NULL; char* name = NULL; if (curSettings->next_turn == WHITE) { filename = LABELBLACKCHECKFILENAME; name = LABELBLACKCHECKNAME; } else { filename = LABELWHITECHECKFILENAME; name = LABELWHITECHECKNAME; } int checkLabel_x_location = mainMenuButton_x_location; int checkabel_y_location = mainMenuButton_y_location + BUTTON_H + MARGIN; control* checkLabel_control; if (-1 == Create_panel_from_bmp( filename, name, checkLabel_x_location, checkabel_y_location, GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &checkLabel_control, &error_global)) { guiQuit = -1; return; } UINode* checkLabel_node; if (-1 == CreateAndAddNodeToTree(checkLabel_control, gameBoarBackground_node, &checkLabel_node, &error_global)) { FreeControl(checkLabel_control); guiQuit = -1; return; } } if (gameOver) { Sint16 checkMateLabel_x_location = 0; Sint16 checkMateLabel_y_location = (Sint16)(0.25 * BOARD_H - 20); control* checkMateLabel_control; if (-1 == Create_panel_from_bmp( LABELCHECKMATEFILENAME, LABELCHECKMATENAME, checkMateLabel_x_location, checkMateLabel_y_location, GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &checkMateLabel_control, &error_global)) { guiQuit = -1; return; } UINode* checkMateLabel_node; if (-1 == CreateAndAddNodeToTree(checkMateLabel_control, board_node, &checkMateLabel_node, &error_global)) { FreeControl(checkMateLabel_control); guiQuit = -1; return; } char* filename = NULL; char* name = NULL; if (curSettings->next_turn == WHITE) { filename = LABELBLACKWINSFILENAME; name = LABELBLACKWINSNAME; } else { filename = LABELWHITEWINSFILENAME; name = LABELWHITEWINSNAME; } Sint16 winsLabel_x_location = 0; Sint16 winsLabel_y_location = (Sint16)(0.5 * BOARD_H - 20); control* winsLabel_control; if (-1 == Create_panel_from_bmp( filename, name, winsLabel_x_location, winsLabel_y_location, GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &winsLabel_control, &error_global)) { guiQuit = -1; return; } UINode* winsLabel_node; if (-1 == CreateAndAddNodeToTree(winsLabel_control, board_node, &winsLabel_node, &error_global)) { FreeControl(winsLabel_control); guiQuit = -1; return; } } else if (tie) { Sint16 tieLabel_x_location = 0; Sint16 tieLabel_y_location = (Sint16)(0.25 * BOARD_H - 20); control* tieLabel_control; if (-1 == Create_panel_from_bmp( LABELTIEFILENAME, LABELTIENAME, tieLabel_x_location, tieLabel_y_location, GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &tieLabel_control, &error_global)) { guiQuit = -1; return; } UINode* tieLabel_node; if (-1 == CreateAndAddNodeToTree(tieLabel_control, board_node, &tieLabel_node, &error_global)) { FreeControl(tieLabel_control); guiQuit = -1; return; } Sint16 gameOverLabel_x_location = 0; Sint16 gameOverLabel_y_location = (Sint16)(0.50 * BOARD_H - 20); control* gameOverLabel_control; if (-1 == Create_panel_from_bmp( LABELGAMEOVERFILENAME, LABELGAMEOVERNAME, gameOverLabel_x_location, gameOverLabel_y_location, GAMEBOARDBACKGROUND_W, GAMEBOARDBACKGROUND_H, &gameOverLabel_control, &error_global)) { guiQuit = -1; return; } UINode* gameOverLabel_node; if (-1 == CreateAndAddNodeToTree(gameOverLabel_control, board_node, &gameOverLabel_node, &error_global)) { FreeControl(gameOverLabel_control); guiQuit = -1; return; } } // DrawTree if (-1 == FlipTree(&error_global)) { guiQuit = -1; return; } if (PLAYER_VS_AI_GAME_MODE == curSettings->game_mode && curSettings->next_turn != curSettings->user_color) { ComputerTurn(&error_global); } }