void TicTacToeGame::PlayGame(int index, HWND hWnd, HDC hdc) { if (index != -1) { RECT rc; if ((arrayGameBoard[index] == 0) && GetCellRect(hWnd, index, &rc)) { //FillRect(hdc, &rc, (intPlayerTurn == 1) ? hbPlayerOne : hbPlayerTwo); DrawIconCentered(hdc, &rc, (intPlayerTurn == 1) ? hiPlayerOne : hiPlayerTwo); arrayGameBoard[index] = intPlayerTurn; winner = GetWinner(wins); if (winner == 1 || winner == 2) { ShowWinner(hWnd, hdc); MessageBox(hWnd, (winner == 1) ? L"Player 1 is the winner" : L"Player 2 is the winner", L"You Win", MB_OK | MB_ICONINFORMATION); intPlayerTurn = 0; } else if (winner == 3) { MessageBox(hWnd, L"it's a draw", L"Draw", MB_OK | MB_ICONINFORMATION); intPlayerTurn = 0; } else { intPlayerTurn = (intPlayerTurn == 1) ? 2 : 1; } ShowTurn(hWnd, hdc); } } }
///OnValidMove is called after a valid move. The game ///is either terminated, or the next player can do ///his/her move. void ribi::con3::WtConnectThreeGameDialog::OnValidMove() { if (m_board->GetWinner() == Winner::no_winner) { UpdatePlayersPanel(); return; } m_state = state_winner; this->PauseTimer(); ShowWinner(); }
void TicTacToeGame::DrawGame(HDC hdc, RECT rc, HWND hWnd) { for (int i = 0; i < 4; i++) { DrawLine(hdc, rc.left + TicTacToeGame::CELL_SIZE * i, rc.top, rc.left + TicTacToeGame::CELL_SIZE * i, rc.bottom); DrawLine(hdc, rc.left, rc.top + TicTacToeGame::CELL_SIZE * i, rc.right, rc.top + TicTacToeGame::CELL_SIZE * i); } RECT rcCell; for (int i = 0; i < ARRAYSIZE(arrayGameBoard); i++) { if ((arrayGameBoard[i] != 0) && GetCellRect(hWnd, i, &rcCell)) { DrawIconCentered(hdc, &rcCell, (arrayGameBoard[i] == 1) ? hiPlayerOne : hiPlayerTwo); } } if (winner != 0 && winner != 3) { ShowWinner(hWnd, hdc); } ShowTurn(hWnd, hdc); }