Ejemplo n.º 1
0
        public bool GetMoveFormUser(string i_PlayerName, GameBoard.eBoardSquare i_playerSquare, GameBoard i_GameBoard) //TODO Refactor this and fix logic
        {
            string message             = "Hi {0}, it's your turn. Please Choose a Valid Column or q to forfit";
            string invlaidInputMessage = "Invalid Input Please Choose a Valid Column or q to forfit";
            char   inputChar;
            int    columnChoise;
            bool   playerWantsToPlay = true;
            bool   invalidInput      = true;

            Console.WriteLine(message, i_PlayerName);
            while (invalidInput)
            {
                if (char.TryParse(Console.ReadLine(), out inputChar))
                {
                    if (inputChar == GameUtils.k_ForfitChar)
                    {
                        playerWantsToPlay = false;
                        invalidInput      = false;
                    }
                    else if (char.IsDigit(inputChar))
                    {
                        columnChoise = (int)char.GetNumericValue(inputChar);
                        invalidInput = i_GameBoard.TryToSetColumnSquare(columnChoise - 1, i_playerSquare);
                    }
                }

                if (invalidInput)
                {
                    Console.WriteLine(invlaidInputMessage);
                }
            }

            return(playerWantsToPlay);
        }
Ejemplo n.º 2
0
 private void buildDesicionsTree(TreeNode <GameBoard> root, int depth, bool io_IsComputerPlaying)
 {
     GameBoard.eBoardSquare eBoard = io_IsComputerPlaying ? GameBoard.eBoardSquare.Player2Square : GameBoard.eBoardSquare.Player1Square;
     if (!root.Data.BoardStatus.Equals(GameBoard.eBoardStatus.NextPlayerCanPlay) || depth == 0)
     {
         return;
     }
     for (int i = 0; i < root.Data.Columns; i++)
     {
         GameBoard newBoard     = (GameBoard)root.Data.Clone();
         bool      isColumnFull = newBoard.TryToSetColumnSquare(i, eBoard);
         if (isColumnFull == false)
         {
             root.AddChild(newBoard, i);
         }
         else
         {
             Console.Beep();
         }
     }
     foreach (TreeNode <GameBoard> childNode in root.Children)
     {
         buildDesicionsTree(childNode, depth - 1, !io_IsComputerPlaying);
     }
 }
Ejemplo n.º 3
0
 private void playHumanTurn()
 {
     GameBoard.eBoardSquare playerSquare = m_TurnNumber % 2 == 0 ? GameBoard.eBoardSquare.Player1Square : GameBoard.eBoardSquare.Player2Square;
     m_PlayerWantsToPlay = m_UiManager.GetMoveFormUser(m_Players[m_TurnNumber % 2].Name, playerSquare, m_GameBoard);
 }