コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public void MoveCursorDownShouldMoveDown()
 {
     //Arrange via Setup
     //Act
     _underTest.MoveCursorDown();
     //Assert
     Assert.AreEqual(1, _underTest.PosY);
 }
コード例 #4
0
        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);
        }
コード例 #5
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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        public void DrawBoardShouldDrawSymbolFor8Neighbours()
        {
            //Arrange
            var bus = A.Fake <IServiceBus>();

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

            //Act
            game.MoveCursorRight();
            game.MoveCursorDown();
            game.ClickCoordinate();
            game.MoveCursorUp();
            game.DrawBoard();
            //Assert
            A.CallTo(() => bus.Write("8 ")).MustHaveHappened(Repeated.Exactly.Once);
        }