Beispiel #1
0
        public void Play(char symbol, int x, int y)
        {
            //if first move
            if (_lastSymbol == ' ')
            {
                //if player is X
                if (symbol == 'O')
                {
                    throw new Exception("Invalid first player");
                }
            }
            //if not first move but player repeated
            else if (symbol == _lastSymbol)
            {
                throw new Exception("Invalid next player");
            }
            //if not first move but play on an already played tile
            else if (_board.TileAt(x, y).Symbol != ' ')
            {
                throw new Exception("Invalid position");
            }

            // update game state
            _lastSymbol = symbol;
            _board.AddTileAt(symbol, x, y);
        }
Beispiel #2
0
        public void Play(char symbol, int rowIndex, int columnIndex)
        {
            EnsureFirstPlayerIsX(symbol);
            EnsureCorrectPlayer(symbol);
            EnsureValidPosition(rowIndex, columnIndex);

            _lastSymbol = symbol;
            _board.AddTileAt(symbol, rowIndex, columnIndex);
        }