示例#1
0
        private PlayerMove RunGame(PlayerMove userInputMove, IGameGrid currentGameGrid, bool runAtGameStart)
        {
            var cellUpdater      = Factory.NewCellUpdater();
            var mineUpdater      = MineFactory.NewMineChecker();
            var mineGeneration   = MineFactory.NewMineLocations();
            var gameGridDisplay  = GridFactory.NewDisplayGrid();
            var convertUserInput = Factory.NewUserInputConverter();

            if (runAtGameStart)
            {
                mineUpdater.UpdateCellWithMineStatus(mineGeneration.MineLocations(currentGameGrid.Size), currentGameGrid);
                cellUpdater.UpdateAdjacentMineTotalAtGameStart(currentGameGrid);
            }

            do
            {
                Console.Clear();
                Console.WriteLine(gameGridDisplay.GenerateGameDisplay(currentGameGrid));

                var inputMove = _gameMessageDisplay.ShowUserInputMessage(currentGameGrid.Size);

                userInputMove = convertUserInput.ConvertInputToUserMove(inputMove);
            } while (_userInputValidation.IsCellRevealed(currentGameGrid, userInputMove));

            cellUpdater.UpdateDisplayStatusAfterUserMove(userInputMove, currentGameGrid);

            return(userInputMove);
        }
示例#2
0
        public string EndGameMessage(IGameGrid currentGameGrid, PlayerMove userInputMove)
        {
            var gameGridDisplay  = GridFactory.NewDisplayGrid();
            var revealedGameGrid = gameGridDisplay.GameOverGridDisplay(currentGameGrid);

            var message = currentGameGrid.GeneratedGameCell[userInputMove.Row, userInputMove.Column]
                          .IsMine
                    ? $"Sorry, you have lost.{Environment.NewLine}Game over!"
                    : $"Congrats!{Environment.NewLine}You have won!";

            return(revealedGameGrid + message);
        }
示例#3
0
        public void DisplayABoardWithTheCorrectDimensions(int size, string expected)
        {
            //Arrange
            var newDisplay = GridFactory.NewDisplayGrid();
            var gameGrid   = GridFactory.NewGameGrid(size);

            //Act
            var result = newDisplay.GenerateGameDisplay(gameGrid);

            //Assert
            Assert.Equal(expected, result);
        }
示例#4
0
        public void DisplayBoardWithGeneratedMinesCorrectly()
        {
            //Arrange
            var gridSize      = 2;
            var newGrid       = GridFactory.NewGameGrid(gridSize);
            var gameDisplay   = GridFactory.NewDisplayGrid();
            var mineLogic     = MineFactory.NewMineChecker();
            var mineLocations = new StubForTwoMineLocations();

            mineLogic.UpdateCellWithMineStatus(mineLocations.MineLocations(gridSize), newGrid);

            //Act

            var result = gameDisplay.GenerateGameDisplay(newGrid);

            //Assert
            Assert.Equal(". + \n+ . \n", result);
        }