Exemple #1
0
 public static char GetPlayerChar(TicTacToePlayer player)
 {
     return(player == TicTacToePlayer.None ? ' '
          : player == TicTacToePlayer.Tic ? 'X'
          : player == TicTacToePlayer.Tac ? 'O'
          : '?'
            );
 }
Exemple #2
0
        public TicTacToeAction(int position, TicTacToePlayer player)
        {
            if (position < 0 || position > 8)
            {
                throw new ArgumentException("position must be between 0 and 8, inclusive", nameof(position));
            }

            Position = position;
            Player   = player;
        }
Exemple #3
0
        protected TicTacToePlayer CheckChainForWinner(List <TicTacToePlayer> chain)
        {
            // We only verify that all the players in the list are the same, the length needs to be the length to win
            if (chain.Count != ChainForWin)
            {
                return(TicTacToePlayer.None);
            }

            TicTacToePlayer leader = chain[0];

            foreach (var p in chain)
            {
                if (p != leader)
                {
                    return(TicTacToePlayer.None);
                }
            }

            return(leader);
        }
Exemple #4
0
 public TicTacToeGame()
 {
     NewGame();
     CurrentPlayer = TicTacToePlayer.Tic;
 }
Exemple #5
0
 public void NextPlayer()
 {
     CurrentPlayer = CurrentPlayer == TicTacToePlayer.Tic
         ? TicTacToePlayer.Tac
         : TicTacToePlayer.Tic;
 }