Пример #1
0
        public void ShouldRevealAllNonMineAdjacentCells_WhenRevealCellWithNoAdjacentMine()
        {
            var mineCountState = new List <int>
            {
                0, 0, 0, 0,
                1, 1, 1, 0,
                1, 0, 1, 0,
                1, 1, 1, 0
            };
            var gameBoard = SetupGameBoardWithMineCounts(mineCountState);

            var playCoordinate = new Coordinate(1, 1); // coordinate of a cell with no adjacent mine
            var revealCommand  = new RevealCommand(playCoordinate);

            revealCommand.Execute(gameBoard);

            var result             = gameBoard.BoardState.Select(c => c.CellState);
            var expectedBoardState = new List <CellState>
            {
                CellState.Revealed, CellState.Revealed, CellState.Revealed, CellState.Revealed,
                CellState.Revealed, CellState.Revealed, CellState.Revealed, CellState.Revealed,
                CellState.Unrevealed, CellState.Unrevealed, CellState.Revealed, CellState.Revealed,
                CellState.Unrevealed, CellState.Unrevealed, CellState.Revealed, CellState.Revealed,
            };

            Assert.Equal(expectedBoardState, result);
        }
Пример #2
0
        public void ShouldSetSelectedCellStateToRevealed_WhenExecuted()
        {
            var revealCoordinate = new Coordinate(1, 1);
            var revealCommand    = new RevealCommand(revealCoordinate);
            var gameBoard        = new GameBoard(5, 5);

            revealCommand.Execute(gameBoard);

            var result = gameBoard.GetCell(revealCoordinate).CellState;

            Assert.Equal(CellState.Revealed, result);
        }
Пример #3
0
        public void ShouldThrowInvalidMoveException_WhenExecuteOnAlreadyRevealedCell()
        {
            var revealCoordinate = new Coordinate(1, 1);
            var revealCommand    = new RevealCommand(revealCoordinate);

            // set Cell cellState to 'Revealed' before the reveal command is executed
            var gameBoard = new GameBoard(5, 5);

            gameBoard.GetCell(revealCoordinate).CellState = CellState.Revealed;

            Assert.Throws <InvalidMoveException>(() => revealCommand.Execute(gameBoard));
        }
Пример #4
0
        public List<Square> Update(RevealCommand command, PlayerState player)
        {
            var square = _squares[command.Index];
              var changed = new List<Square>();

              if (square.Revealed || square.Flagged)
              {

              }
              else if (square.Mined)
              {
            player.Dead = true;
            square.Revealed = true;
            changed.Add(square);
              }
              else
              {
            int y = command.Index / width;
            int x = command.Index % width;
            var revealed = Reveal(x, y);
            changed.AddRange(revealed);
              }

              return changed;
        }