private bool updatePlayerMoveAndCheckIfQuit(GameBoard.eSymbols i_PlayerSymbol)
        {
            bool userQuit = false;

            for (;;)
            {
                int chosenRow = enterValidRowInput();
                int chosenCol = enterValidColumInput();

                if (chosenCol == -1)
                {
                    userQuit = true;
                    break;
                }

                if (m_Game.CheckIfCellIsAvailable(chosenRow, chosenCol))
                {
                    m_Game.UpdateCellInBoardGame(chosenRow, chosenCol, i_PlayerSymbol);
                    break;
                }
                else
                {
                    Console.WriteLine(@"This cell isn't available, please try another.{0}", Environment.NewLine);
                }
            }

            return(userQuit);
        }
Example #2
0
        public bool GameOver(out string o_Reason)
        {
            bool gameOver = false;

            o_Reason = null;

            if (m_LastPlayer != null)
            {
                GameBoard.eSymbols symbol = m_LastPlayer.PlayerSymbol;
                if (m_Board.FullColum(symbol) || m_Board.FullRow(symbol) || m_Board.FullLeftDiagonal(symbol) || m_Board.FullRightDiagonal(symbol))
                {
                    o_Reason = "A Win!";
                    if (m_LastPlayer == r_Player1)
                    {
                        r_Player2.GamePoints++;
                    }
                    else
                    {
                        r_Player1.GamePoints++;
                    }

                    gameOver = true;
                }
            }

            if (!gameOver && m_Board.BoradIsFull(m_MovesCounter))
            {
                o_Reason = "A Tie!";
                gameOver = true;
            }

            return(gameOver);
        }
        private void playerVsComputerGame()
        {
            Console.WriteLine();
            string playerName = enterPlayerName();

            GameBoard.eSymbols playerSymbol   = enterPlayerSymbol();
            GameBoard.eSymbols computerSymbol = (playerSymbol == GameBoard.eSymbols.Symbol1) ? GameBoard.eSymbols.Symbol2 : GameBoard.eSymbols.Symbol1;
            PlayerDetails      player1        = new PlayerDetails(playerName, playerSymbol);
            PlayerDetails      computer       = new PlayerDetails("Computer", computerSymbol);

            m_Game = new TicTacToeLogic(player1, computer);
            m_Game.SetNewBoard(m_BoardGameLenght, m_BoardGameLenght);
            play((int)eGameMode.PlayerVSComputer);
            printGoodbyeMsg();
        }
        private void playerVsPlayerGame()
        {
            Console.Write("{0}Player 1 - ", Environment.NewLine);
            string player1Name = enterPlayerName();

            Console.Write("Player 2 - ");
            string player2Name = enterPlayerName();

            Console.Write("{0}{1} : ", Environment.NewLine, player1Name);
            GameBoard.eSymbols player1Symbol = enterPlayerSymbol();
            GameBoard.eSymbols player2Symbol = (player1Symbol == GameBoard.eSymbols.Symbol1) ? GameBoard.eSymbols.Symbol2 : GameBoard.eSymbols.Symbol1;
            PlayerDetails      player1       = new PlayerDetails(player1Name, player1Symbol);
            PlayerDetails      Player2       = new PlayerDetails(player2Name, player2Symbol);

            m_Game = new TicTacToeLogic(player1, Player2);
            m_Game.SetNewBoard(m_BoardGameLenght, m_BoardGameLenght);
            play((int)eGameMode.PlayerVSPlayer);
            printGoodbyeMsg();
        }
        private string convertSymbolToString(GameBoard.eSymbols i_PlayerSymbol)
        {
            string symbol = null;

            switch (i_PlayerSymbol)
            {
            case GameBoard.eSymbols.Symbol1:
            {
                symbol = "X";
                break;
            }

            case GameBoard.eSymbols.Symbol2:
            {
                symbol = "O";
                break;
            }
            }

            return(symbol);
        }
Example #6
0
 public PlayerDetails(string i_PlayerName, GameBoard.eSymbols i_PlayerChoosedSymbol)
 {
     r_PlayerName   = i_PlayerName;
     r_PlayerSymbol = i_PlayerChoosedSymbol;
     m_GamePoints   = 0;
 }
Example #7
0
 public void UpdateCellInBoardGame(int i_ChosenRow, int i_ChosenColum, GameBoard.eSymbols i_PlayerSymbol)
 {
     m_Board.SetCellValue(i_ChosenRow, i_ChosenColum, i_PlayerSymbol);
 }
 private void updatePlayerMove(int i_X, int i_Y, GameBoard.eSymbols i_PlayerSymbol)
 {
     r_GameLogic.UpdateCellInBoardGame(i_X, i_Y, i_PlayerSymbol);
 }