Esempio n. 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);
        }
Esempio n. 2
0
        protected void PopulateMines()
        {
            MineFactory Mf = new MineFactory();

            MinesPack.AddRange(Mf.GetAllMines());
            MinesOnBoard.Add(MinesOnBoardLvl1);
            MinesOnBoard.Add(MinesOnBoardLvl2);
            MinesOnBoard.Add(MinesOnBoardLvl3);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public Board CreateRandomBoard(GameSettings settings)
        {
            this.Board = new Board(settings.BoardSize);

            Random      rnd         = new Random();
            List <int>  choices     = Enumerable.Range(0, settings.BoardSize * settings.BoardSize).ToList();
            MineFactory mineFactory = new MineFactory();

            // Simple Mine
            Tile tileWithMine0 = new Tile();

            tileWithMine0.Mine = mineFactory.CreateMine(0);

            // Wide Mine
            Tile tileWithMine1 = new Tile();

            tileWithMine1.Mine = mineFactory.CreateMine(1);

            // Fake Mine
            Tile tileWithMine2 = new Tile();

            tileWithMine2.Mine = mineFactory.CreateMine(2);

            for (int i = 0; i < settings.SimpleMineCount; i++)
            {
                int choicesIndex = rnd.Next(0, choices.Count);
                this.Board.Tiles[choices[choicesIndex]] = (Tile)tileWithMine0.Clone();
                choices.RemoveAt(choicesIndex);
            }
            for (int i = 0; i < settings.WideMineCount; i++)
            {
                int choicesIndex = rnd.Next(0, choices.Count);
                this.Board.Tiles[choices[choicesIndex]] = (Tile)tileWithMine1.Clone();
                choices.RemoveAt(choicesIndex);
            }
            for (int i = 0; i < settings.FakeMineCount; i++)
            {
                int choicesIndex = rnd.Next(0, choices.Count);
                this.Board.Tiles[choices[choicesIndex]] = (Tile)tileWithMine2.Clone();
                choices.RemoveAt(choicesIndex);
            }

            return(this.Board);
        }
        public void ShowTheCorrectGameWinningMessageWhenAPlayerCompletesAGridWithoutHittingAMine()
        {
            //Arrange
            var gridSize          = 2;
            var newMessageDisplay = Factory.NewMessageDisplay();
            var gameGrid          = GridFactory.NewGameGrid(gridSize);
            var gameCellUpdater   = Factory.NewCellUpdater();
            var mineUpdater       = MineFactory.NewMineChecker();
            var mineStub          = new StubForTwoMineLocations();
            var userMove          = new PlayerMove(0, 1);
            var expected          =
                $"* 2 {Environment.NewLine}* 2 {Environment.NewLine}Congrats!{Environment.NewLine}You have won!";

            //Act
            mineUpdater.UpdateCellWithMineStatus(mineStub.MineLocations(gridSize), gameGrid);
            gameCellUpdater.UpdateAdjacentMineTotalAtGameStart(gameGrid);
            var result = newMessageDisplay.EndGameMessage(gameGrid, userMove);

            //Assert
            Assert.Equal(expected, result);
        }
        public void ShowTheCorrectGameLosingMessageWhenAPlayerHitsAMine()
        {
            //Arrange
            var gridSize          = 2;
            var newMessageDisplay = Factory.NewMessageDisplay();
            var gameGrid          = GridFactory.NewGameGrid(gridSize);
            var gameCellUpdater   = Factory.NewCellUpdater();
            var mineUpdater       = MineFactory.NewMineChecker();
            var mineStub          = new StubForTwoMineLocations();
            var userMove          = new PlayerMove(0, 0);
            var expected          =
                $"* 2 {Environment.NewLine}* 2 {Environment.NewLine}Sorry, you have lost.{Environment.NewLine}Game over!";

            //Act
            mineUpdater.UpdateCellWithMineStatus(mineStub.MineLocations(gridSize), gameGrid);
            gameCellUpdater.UpdateAdjacentMineTotalAtGameStart(gameGrid);
            var result = newMessageDisplay.EndGameMessage(gameGrid, userMove);

            //Assert
            Assert.Equal(expected, result);
        }
Esempio n. 7
0
 public void CreateFactory()
 {
     this.factory = new MineFactory();
 }
Esempio n. 8
0
 public MineFactoryAdapter(string token, string roomId)
     : base(token, roomId)
 {
     _mineFactory = new MineFactory();
 }