Example #1
0
 private bool ProcessTurnsAndAskToPlayAgain()
 {
     while (true)
     {
         NextPlayer();
         _board.Display();
         if (_currentPlayer.AI != null) //it's an AI player
         {
             _board.AddMark(_currentPlayer.Mark, _currentPlayer.AI.TakeTurn(_board.BoardArray));
             Console.Clear();
             _board.Display();
             Console.ForegroundColor = _currentPlayer.TextColor;
             Console.Write("              " + _currentPlayer.Name + " has spoken!");
             Console.ResetColor();
             Thread.Sleep(1000);
         }
         else
         {
             PromptUser();
         }
         //check for victory or tie and ask to play again
         if (_board.IsVictory(_currentPlayer))
         {
             _board.Display();
             Console.ForegroundColor = _currentPlayer.TextColor;
             TextEffects.CenterAlignWriteLine(_currentPlayer.Name + " wins!");
             Console.ResetColor();
             return(AskToPlayAgain());
         }
         else if (_board.IsCatGame())
         {
             _board.Display();
             Console.ForegroundColor = TextEffects.NeutralColor;
             Console.WriteLine(TextEffects.offsetString + "Cats game!");
             Console.ResetColor();
             return(AskToPlayAgain());
         }
     }
 }
Example #2
0
        private void PromptUser()
        {
            bool validInput = false;
            int  position;

            while (!validInput)
            {
                Console.Write("{0} enter a board position: ", _currentPlayer.Name);
                validInput = int.TryParse(Console.ReadLine(), out position);

                if (!validInput)
                {
                    Console.WriteLine("Invalid entry!");
                    continue;
                }

                validInput = _board.AddMark(_currentPlayer.Mark, position);
            }
        }