Exemplo n.º 1
0
        // Returns a string describing the state of the game
        public override string ToString()
        {
            string xName = PlayerX.GetType().Name;
            string oName = PlayerO.GetType().Name;

            if (Status == null)
            {
                // Game is ongoing
                return(Turn +
                       $" : It's {(Turn == CellState.X ? xName : oName)} turn");
            }
            else
            {
                // Game is finished

                // Did someone make an illegal move?
                if (overrideWinner != CellState.Undecided)
                {
                    return(string.Format(
                               "Game Over : {0} wins since {1} made illegal move",
                               Status == CellState.X ? xName : oName,
                               Status != CellState.X ? xName : oName));
                }

                // Game ended within the rules
                return("Game Over : " +
                       (Status != CellState.Undecided
                        ? $"{Status} ({(Status == CellState.X ? xName : oName)}) wins"
                        : "It's a draw"));
            }
        }
Exemplo n.º 2
0
 public void PlayerMoved()
 {
     if (CurrentTurn == Turn.PlayerX)
     {
         if (PlayerX.GetType() == typeof(HumanPlayer))
         {
             PlayerX.OnPlayerMoved();
         }
     }
     else
     {
         if (PlayerO.GetType() == typeof(HumanPlayer))
         {
             PlayerO.OnPlayerMoved();
         }
     }
 }