private void noFreePlaceOnBoardOrNoOneCanPlaySoFinishTheGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard) { i_OtheloGameBoard.CountAndUpdateHowManySignalsOnBoardFromAnyKind(); printWhoIsTheWinnerOfTheCurrentGame(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard); }
// $G$ DSN-999 (-5) this method is to long - should be divided to several methods private void startPlayOtheloGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard) { const bool v_HasFreePlaceOnBoardGame = true; const bool v_WantToPlayAnotherGameWithTheSamePlayer = true; const bool v_CurrentPlayerCanContinueThisTurn = true; const bool v_UserChoiseIsLegal = true; const bool v_TwoPlayersCanNotMoveInTheGame = true; const bool v_UserWantToStartNewGame = true; const int k_TimeToDelay = 3000; bool wantStartNewGame = true; bool currentPlayerCanPlayThisTurn = true; int[] positionFromUserInTheBoard; while (wantStartNewGame == v_UserWantToStartNewGame) { while (i_OtheloGameBoard.CheckTheOtheloBoardGameHasFreePlace() == v_HasFreePlaceOnBoardGame) { // There are still empty cells on board - continue the game i_OtheloGameBoard.PrintOtheloGameBoard(); i_OtheloGameBoard.CountAndUpdateHowManySignalsOnBoardFromAnyKind(); checkIfPrintMsgAboutTheCurrentPlayerHasNothingToDoThisTurn(ref currentPlayerCanPlayThisTurn); printTheCurrentUserTurn(i_FirstPlayer.PlayerName, i_SecondPlayer.PlayerName); if (s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(s_CurrentSignalTurn, i_OtheloGameBoard, i_SecondPlayer) == v_CurrentPlayerCanContinueThisTurn) { // If it's regular player turn ( not the computer ) if ((s_CurrentSignalTurn == k_FirstPlayerSignal) || (s_CurrentSignalTurn == k_SecondPlayerSignal && i_SecondPlayer.StateGame != OtheloGameBoard.eGameTypes.Computer)) { // There is atleast one option to the current player to continue in this turn currentPlayerCanContinueToPlayThisTurn(i_OtheloGameBoard, out positionFromUserInTheBoard); /* In case it is possible the current player to continue and he want to put his signal in empty position on the board, * so now you have to check if it's legal */ while (s_OtheloGamePolicy.CheckTheUserChoiseIsLegal(s_CurrentSignalTurn, i_OtheloGameBoard, positionFromUserInTheBoard) != v_UserChoiseIsLegal) { // In case the user chose illegal position - try insert new position Console.WriteLine("Illegal position!!! You can put your signal only if you block the other player!"); currentPlayerCanContinueToPlayThisTurn(i_OtheloGameBoard, out positionFromUserInTheBoard); } // In case the position from user is legal - so do it! s_OtheloGamePolicy.PutSignalInTheRequiredUserPositionOnBoard(i_OtheloGameBoard, s_CurrentSignalTurn, positionFromUserInTheBoard); } else if (s_CurrentSignalTurn == k_SecondPlayerSignal && i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer) { // In case it's second player turn and it's the COMPUTER s_OtheloGamePolicy.PutAutomaticSignalOfCompuerOnBoard(i_OtheloGameBoard, s_CurrentSignalTurn); System.Threading.Thread.Sleep(k_TimeToDelay); } } else { // In case the current player has nothing to do currentPlayerCanPlayThisTurn = !currentPlayerCanPlayThisTurn; } /* In case there isn't possible way to current player to continue this turn - so move to the other player * We arrive here also when the current player finish his turn and we continue to the other player*/ if (checkTheTwoPlayersCanNotMoveInTheGame(i_OtheloGameBoard, i_SecondPlayer) == v_TwoPlayersCanNotMoveInTheGame) { printMassageInCaseTwoPlayersCanNotMoveInTheGame(i_OtheloGameBoard); break; } changeTurnToTheOtherPlayer(); } // No free place on board game or no one from the players can play - so finish the current game and display the points status noFreePlaceOnBoardOrNoOneCanPlaySoFinishTheGame(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard); if (askAboutAnotherGameWithTheSamePlayer() != v_WantToPlayAnotherGameWithTheSamePlayer) { printMsgAboutLeaveTheGame(); wantStartNewGame = !wantStartNewGame; // Dont start an new game } else { // Want to start an new game startNewGame(i_OtheloGameBoard); } } }