private void restartGame(HumanPlayer i_WhiteHumanPlayer, HumanPlayer i_BlackHumanPlayer, PcPlayer i_BlackPCPlayer) { // this method restarts a game. initialize(i_WhiteHumanPlayer, i_BlackHumanPlayer, i_BlackPCPlayer); }
public void Run() { // this method maintains the main loop of the game. HumanPlayer whiteHumanPlayer = new HumanPlayer(GameUtilities.ePlayerColor.WhitePlayer); HumanPlayer blackHumanPlayer = new HumanPlayer(GameUtilities.ePlayerColor.BlackPlayer); PcPlayer blackPCPlayer = new PcPlayer(); int currentPlayerMoveRowIndex, currentPlayerMoveColumnIndex; bool isPlayerMoveLegal, isGameEnd = false; List <Cell> cellsToUpdate = new List <Cell>(); eGameDecision rematchOrExit; configureGameSettings(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer); initialize(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer); while (true) { UI.Draw(m_GameBoard, whiteHumanPlayer, blackHumanPlayer, blackPCPlayer); do { tellCurrentPlayerToPlay(blackHumanPlayer, whiteHumanPlayer, blackPCPlayer, m_BlackPlayerOptions, out currentPlayerMoveRowIndex, out currentPlayerMoveColumnIndex); if (currentPlayerMoveColumnIndex == (int)HumanPlayer.eUserRequest.Exit) { isGameEnd = true; break; } isPlayerMoveLegal = isLegalMove(currentPlayerMoveRowIndex, currentPlayerMoveColumnIndex, ref cellsToUpdate); if (!isPlayerMoveLegal) { UI.InformPlayerItMoveIsntAnOption(m_PlayerTurn); } }while (!isPlayerMoveLegal); if (isGameEnd) { // the user chose to exit the game. break; } m_GameBoard.UpdateBoard(cellsToUpdate, m_PlayerTurn); updatePlayersOptions(); updatePlayersScore(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer); turnChangingManager(); isGameEnd = isGameOver(); Ex02.ConsoleUtils.Screen.Clear(); if (isGameEnd) { determineWinner(); rematchOrExit = UI.AskUserForRematchOrExit(); if (rematchOrExit == eGameDecision.Rematch) { isGameEnd = false; restartGame(whiteHumanPlayer, blackHumanPlayer, blackPCPlayer); } else { // the user chose to exit game break; } } } UI.ShowExitMessage(); System.Threading.Thread.Sleep(5000); }