Exemplo n.º 1
0
        public void Play()
        {
            while (BoardIsNotRevealed())
            {
                var newLocation = CreateLocationBasedOnInput();

                RevealTheSquareIfLocationIsOnBoard(newLocation);

                if (WinLoseChecker.IsLosingConditionWhenOneMineIsRevealed(Board))
                {
                    _output.Write(GameInstruction.GameOverMessage);
                    Board.RevealAllSquares();
                    State = GameState.Lose;
                    _output.Write(GameInstruction.ResultMessage + State);
                }
                else if (WinLoseChecker.IsWinningConditionWhenAllHintsAreRevealed(Board))
                {
                    _output.Write(GameInstruction.GameOverMessage);
                    Board.RevealAllSquares();
                    State = GameState.Win;
                    _output.Write(GameInstruction.ResultMessage + State);
                }

                _output.Write(GameInstruction.DisplayCurrentBoardMessage);
                DisplayBoard();
            }
        }
Exemplo n.º 2
0
        public void IsLosingConditionShould_ReturnFalse_WhenNoMineOnBoardIsRevealed()
        {
            var board         = Board.CreateEmptyBoard(2);
            var mineGenerator = new MockMinesGenerator();

            mineGenerator.PlaceMines(2, board);
            var result = WinLoseChecker.IsLosingConditionWhenOneMineIsRevealed(board);

            Assert.False(result);
        }
Exemplo n.º 3
0
        public void IsLosingConditionShould_ReturnTrue_WhenOneMineOnBoardAreRevealed()
        {
            var board         = Board.CreateEmptyBoard(2);
            var mineGenerator = new MockMinesGenerator();

            mineGenerator.PlaceMines(2, board);
            var topLeft = new Location(0, 0);
            var mineOne = board.GetSquare(topLeft);

            mineOne.Reveal();
            var result = WinLoseChecker.IsLosingConditionWhenOneMineIsRevealed(board);

            Assert.True(result);
        }