public void ClickCoordinateShouldOnlyOpenOneCoordinateEastOfMine()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

            A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(2, 2);
            var game      = new MineSweeperGame(5, 5, 1, bus);
            int openCount = 0;

            //Act
            game.MoveCursorRight();
            game.MoveCursorRight();
            game.MoveCursorRight();
            game.MoveCursorDown();
            game.MoveCursorDown();
            game.ClickCoordinate();
            //Assert
            for (int y = 0; y < game.SizeY; y++)
            {
                for (int x = 0; x < game.SizeX; x++)
                {
                    if (game.GetCoordinate(x, y).IsOpen)
                    {
                        openCount++;
                    }
                }
            }
            Assert.AreEqual(1, openCount);
        }
        public void FlagCoordinateShouldUsePosXAndPosY()
        {
            //Arrange via setup
            //Act
            _underTest.MoveCursorRight();
            _underTest.MoveCursorDown();
            _underTest.FlagCoordinate();
            var coord = _underTest.GetCoordinate(1, 1);

            //Assert
            Assert.AreEqual(coord.IsFlagged, true);
        }
Esempio n. 3
0
        public void DrawBoardShouldDrawSymbolForFlag()
        {
            //Arrange
            var bus  = A.Fake <IServiceBus>();
            var game = new MineSweeperGame(2, 2, 0, bus);

            //Act
            game.FlagCoordinate();
            game.MoveCursorRight();
            game.DrawBoard();
            //Assert
            A.CallTo(() => bus.Write("! ")).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 4
0
 public void MoveCursorRightShouldMoveRight()
 {
     //Arrange via Setup
     //Act
     _underTest.MoveCursorRight();
     //Assert
     Assert.AreEqual(1, _underTest.PosX);
 }
Esempio n. 5
0
        public void DrawBoardShouldDrawSymbolForMine()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

            A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0);
            var game = new MineSweeperGame(2, 2, 1, bus);

            //Act
            game.ClickCoordinate();
            game.MoveCursorRight();
            game.DrawBoard();
            //Assert
            A.CallTo(() => bus.Write("X ")).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void ClickCoordinateShouldUsePosXAndPosY()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

            A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0);
            var game = new MineSweeperGame(2, 2, 1, bus);

            //Act
            game.MoveCursorRight();
            game.MoveCursorDown();
            game.ClickCoordinate();
            //Assert
            Assert.AreEqual(true, game.GetCoordinate(1, 1).IsOpen);
        }
Esempio n. 7
0
        public void DrawBoardShouldDrawMarkedPositionBasedOnPosXAndPosY()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

            A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(0, 0, 1, 0);
            var game = new MineSweeperGame(3, 3, 2, bus);

            //Act
            game.MoveCursorRight();
            game.MoveCursorDown();
            game.ClickCoordinate();
            game.DrawBoard();
            //Assert
            A.CallTo(() => bus.Write("2 ", ConsoleColor.DarkCyan)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void ClickCoordinateShouldDetectGameLoss()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

            A.CallTo(() => bus.Next(A <int> .Ignored)).ReturnsNextFromSequence(1, 1);
            var game = new MineSweeperGame(2, 2, 1, bus);

            //Act
            game.MoveCursorRight();
            game.MoveCursorDown();
            game.ClickCoordinate();
            //Assert

            Assert.AreEqual(GameState.Lost, game.State);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            KeyboardState kbState = Keyboard.GetState();

            if (gameLogic.State == GameState.Playing)
            {
                if (kbState.IsKeyDown(Keys.Left) && prevState.IsKeyUp(Keys.Left))
                {
                    gameLogic.MoveCursorLeft();
                }
                if (kbState.IsKeyDown(Keys.Right) && prevState.IsKeyUp(Keys.Right))
                {
                    gameLogic.MoveCursorRight();
                }
                if (kbState.IsKeyDown(Keys.Up) && prevState.IsKeyUp(Keys.Up))
                {
                    gameLogic.MoveCursorUp();
                }
                if (kbState.IsKeyDown(Keys.Down) && prevState.IsKeyUp(Keys.Down))
                {
                    gameLogic.MoveCursorDown();
                }
                if (kbState.IsKeyDown(Keys.Space) && prevState.IsKeyUp(Keys.Space))
                {
                    gameLogic.ClickCoordinate();
                }
                if (kbState.IsKeyDown(Keys.Enter) && prevState.IsKeyUp(Keys.Enter))
                {
                    gameLogic.FlagCoordinate();
                }
            }
            else
            {
                if (kbState.IsKeyDown(Keys.Space) && prevState.IsKeyUp(Keys.Space))
                {
                    gameLogic.ResetBoard();
                }
            }

            prevState = kbState;
            base.Update(gameTime);
        }