예제 #1
0
        private void printWhoIsTheWinnerOfTheCurrentGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard)
        {
            char   theWinnerOfTheCurrentGame;
            string msgAboutTheWinner;

            theWinnerOfTheCurrentGame = s_OtheloGamePolicy.CheckWhoIsTheWinnerOfTheCurrentGame(i_OtheloGameBoard, i_FirstPlayer, i_SecondPlayer);

            if (theWinnerOfTheCurrentGame == 'X')
            {
                msgAboutTheWinner = string.Format("{0} is the winner  :))))))", i_FirstPlayer.PlayerName);

                printMsgAboutTheWinner(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
            else if (theWinnerOfTheCurrentGame == 'O')
            {
                msgAboutTheWinner = string.Format("{0} is the winner :))))))", i_SecondPlayer.PlayerName);

                printMsgAboutTheWinner(i_SecondPlayer, i_FirstPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
            else
            {
                // FirstPlayer signals == SecondPlayer signals on board
                msgAboutTheWinner = string.Format("There is no winner this game", i_FirstPlayer.PlayerName);

                printMsgAboutTheWinner(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard, msgAboutTheWinner);
            }
        }
예제 #2
0
        public OtheloGameRules(int i_SizeOfGameBoard, OtheloGamePlayer i_SecondPlayer)
        {
            m_AllCurrentLegalMovesMatrix = new char[i_SizeOfGameBoard, i_SizeOfGameBoard];

            if (i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer)
            {
                m_ListWithTheCurrentPositinsOptionsOnBoardForRandom = new List <int>();
            }
        }
예제 #3
0
        private void welcomeAndInitializeFirstPlayer(out OtheloGamePlayer o_FirstPlayer)
        {
            string firstPlayerName;

            Console.WriteLine(@"                                                   
                                            Hello:) Welcome to Othelo game

                                               Please enter your name :");

            firstPlayerName = getNameAndCheckIfNameIsNoLonger();

            o_FirstPlayer = new OtheloGamePlayer(firstPlayerName, k_FirstPlayerSignal, OtheloGameBoard.eGameTypes.Player);
        }
예제 #4
0
        private void initializeOtheloGameAgainstAnotherPlayer(out OtheloGamePlayer o_SecondPlayer)
        {
            string secondPlayerName;

            Console.WriteLine(@"                                                   
                                        O.K! you chose to play with another player 

                                     So, please enter the name of the second player :");

            secondPlayerName = getNameAndCheckIfNameIsNoLonger();

            o_SecondPlayer = new OtheloGamePlayer(secondPlayerName, k_SecondPlayerSignal, OtheloGameBoard.eGameTypes.Player);
        }
예제 #5
0
        private void chooseAndInitializePlayerToPlayWith(out OtheloGamePlayer o_SecondPlayer)
        {
            int playerChoise;

            playerChoise = getUserChoiseToPlayWith();

            o_SecondPlayer = new OtheloGamePlayer();

            switch (playerChoise)
            {
            case 1: initializeOtheloGameAgainstAnotherPlayer(out o_SecondPlayer);
                break;

            case 2: initializeOtheloGameAgainstTheComputer(out o_SecondPlayer);
                break;
            }
        }
예제 #6
0
        public bool CheckIfCurrentPlayerHasOptionToContinueThisTurn(char i_CurrentSignalTurn, OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_SecondPlayer)
        {
            const bool v_LegalMovesMatrixEmptyFromCurrentSignalTurn = true;
            bool       currentPlayerHasOptionToContinueThisTurn     = true;

            zeroTheLegalMovesMatrix(i_OtheloGameBoard);

            if (i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer && m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Count != 0)
            {
                m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Clear();
            }

            createCurrentLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_SecondPlayer);

            if (checkIfLegalMovesMatrixEmptyFromCurrentSignalTurn(i_CurrentSignalTurn, i_OtheloGameBoard) == v_LegalMovesMatrixEmptyFromCurrentSignalTurn)
            {
                currentPlayerHasOptionToContinueThisTurn = !currentPlayerHasOptionToContinueThisTurn;
            }

            return(currentPlayerHasOptionToContinueThisTurn);
        }
예제 #7
0
        public char CheckWhoIsTheWinnerOfTheCurrentGame(OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer)
        {
            char theWinnerOfTheCurrentGame;

            if (i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard > i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard)
            {
                theWinnerOfTheCurrentGame = k_PlayerSignalKind1;
            }
            else if (i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard < i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard)
            {
                theWinnerOfTheCurrentGame = k_PlayerSignalKind2;
            }
            else
            {  // FirstPlayer signals == SecondPlayer signals on board
                theWinnerOfTheCurrentGame = k_NoWinnerInTheGame;
            }

            i_FirstPlayer.PlayerPoints  = i_OtheloGameBoard.NumOfFirstPlayerSignalsOnBoard;
            i_SecondPlayer.PlayerPoints = i_OtheloGameBoard.NumOfSecondPlayerSignalsOnBoard;

            return(theWinnerOfTheCurrentGame);
        }
예제 #8
0
        private void fillSpecificCellInLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, int i_RowIndex, int i_ColumnIndex, OtheloGamePlayer i_SecondPlayer)
        {
            const bool v_LegalMove = true;

            if (checkIfLegalMoveAndUpdateLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_RowIndex, i_ColumnIndex) == v_LegalMove)
            {
                // Fill the specific cell in the legal moves matrix with the current signal turn
                this.m_AllCurrentLegalMovesMatrix[i_RowIndex, i_ColumnIndex] = i_CurrentSignalTurn;

                // Fill the List with the relevent matrix indexes cell - For the random action later
                if (i_SecondPlayer.StateGame == OtheloGameBoard.eGameTypes.Computer)
                {
                    m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Add(i_RowIndex);    // Put the row index of cell in the even place of the list
                    m_ListWithTheCurrentPositinsOptionsOnBoardForRandom.Add(i_ColumnIndex); // Put the column index of cell in the odd place of the list
                }
            }
        }
예제 #9
0
 private void fillCurrentLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, OtheloGamePlayer i_SecondPlayer)
 {
     for (int i = 0; i < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; i++)
     {
         for (int j = 0; j < i_OtheloGameBoard.OtheloGameBoardMatrixDimension; j++)
         {
             fillSpecificCellInLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i, j, i_SecondPlayer);
         }
     }
 }
예제 #10
0
 private void createCurrentLegalMovesMatrix(OtheloGameBoard i_OtheloGameBoard, char i_CurrentSignalTurn, OtheloGamePlayer i_SecondPlayer)
 {
     fillCurrentLegalMovesMatrix(i_OtheloGameBoard, i_CurrentSignalTurn, i_SecondPlayer);
 }
예제 #11
0
        private void printMsgAboutTheWinner(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard, string i_MsgAboutTheWinner)
        {
            string msgAboutCurrentTurn = string.Format(@" GAME OVER ! ! ! {0}  Your points in this game are : {1} : {3} points, {2} : {4} points", i_MsgAboutTheWinner, i_FirstPlayer.PlayerName, i_SecondPlayer.PlayerName, i_FirstPlayer.PlayerPoints, i_SecondPlayer.PlayerPoints);

            Console.WriteLine(msgAboutCurrentTurn);
        }
예제 #12
0
        private void noFreePlaceOnBoardOrNoOneCanPlaySoFinishTheGame(OtheloGamePlayer i_FirstPlayer, OtheloGamePlayer i_SecondPlayer, OtheloGameBoard i_OtheloGameBoard)
        {
            i_OtheloGameBoard.CountAndUpdateHowManySignalsOnBoardFromAnyKind();

            printWhoIsTheWinnerOfTheCurrentGame(i_FirstPlayer, i_SecondPlayer, i_OtheloGameBoard);
        }
예제 #13
0
        private bool checkTheTwoPlayersCanNotMoveInTheGame(OtheloGameBoard i_OtheloGameBoard, OtheloGamePlayer i_SecondPlayer)
        {
            bool       twoPlayersCanNotMoveInTheGame    = true;
            const bool v_FirstPlayerCanContinueTheGame  = true;
            const bool v_SecondPlayerCanContinueTheGame = true;

            if (s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(k_SecondPlayerSignal, i_OtheloGameBoard, i_SecondPlayer) == v_FirstPlayerCanContinueTheGame ||
                s_OtheloGamePolicy.CheckIfCurrentPlayerHasOptionToContinueThisTurn(k_FirstPlayerSignal, i_OtheloGameBoard, i_SecondPlayer) == v_SecondPlayerCanContinueTheGame)
            {
                twoPlayersCanNotMoveInTheGame = !twoPlayersCanNotMoveInTheGame;
            }

            return(twoPlayersCanNotMoveInTheGame);
        }
예제 #14
0
        // $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);
                }
            }
        }
예제 #15
0
 private void initializeOtheloGameAgainstTheComputer(out OtheloGamePlayer o_SecondPlayer)
 {
     o_SecondPlayer = new OtheloGamePlayer(k_PlayAgainstComputer, k_SecondPlayerSignal, OtheloGameBoard.eGameTypes.Computer);
 }