Ejemplo n.º 1
0
 public GhostTests()
 {
     _gameSettings = new TestGameSettings {
         PowerPills = { new CellLocation(50, 50) }
     };
     _gameClock = new TestGameClock();
 }
Ejemplo n.º 2
0
        public GameTests()
        {
            _gameSettings = new TestGameSettings();
            var gameClock = new TestGameClock();

            _game = new Game(gameClock, _gameSettings);
        }
Ejemplo n.º 3
0
        public async Task TheHighScoreDoesNotIncrementAfterEatingACoinIfTheScoreIsNotHigherThanTheCurrentHighScore()
        {
            const int initialHighScore = 1000;

            _highScore = initialHighScore;
            var gameSettings = new TestGameSettings();

            gameSettings.HighScoreStorage = this;
            gameSettings.Coins.Add(gameSettings.PacMan.Location.Below);
            gameSettings.Coins.Add(gameSettings.PacMan.Location.FarAway());

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Down);

            if (gameHarness.Game.HighScore != initialHighScore)
            {
                throw new Exception($"The current high score should be {initialHighScore} not {gameHarness.Game.HighScore}.");
            }

            await gameHarness.EatCoin();

            gameHarness.Game.HighScore.Should().Be(initialHighScore);
        }
Ejemplo n.º 4
0
        public GhostStrategyTests()
        {
            _ghostBuilder = GhostBuilder.New()
                            .WithChaseStrategy(new DirectToStrategy(new DirectToPacManLocation()));

            _gameSettings = new TestGameSettings();
        }
Ejemplo n.º 5
0
        public async Task WeGetAnExtraLifeOnceWhenScoreReachesBonusLifePointAfterScoreIncreasesFromEatingFurtherCoins()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.Coins.Add(gameSettings.PacMan.Location.Below);
            gameSettings.Coins.Add(gameSettings.PacMan.Location.Below.Below);
            gameSettings.Coins.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.PointsNeededForBonusLife = PointsFor.EatingCoin + 1;

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            var previousLives = gameHarness.Lives;

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatCoin();

            using var _ = new AssertionScope();
            await gameHarness.AssertSingleNotificationFires(GameNotification.ExtraPac, async() =>
            {
                await gameHarness.EatCoin();
            });

            gameHarness.Game.Lives.Should().Be(previousLives + 1);
        }
Ejemplo n.º 6
0
        public async Task WeGetAnExtraLifeWhenScoreReachesBonusLifePointAfterEatingAGhost()
        {
            var gameSettings = new TestGameSettings();

            var ghostStart = gameSettings.PacMan.Location.Left.Left.Left;
            var ghost      = GhostBuilder.New()
                             .WithLocation(ghostStart)
                             .WithChaseStrategyRight()
                             .WithScatterStrategyRight()
                             .Create();

            gameSettings.Ghosts.Add(ghost);
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.Left);
            gameSettings.PointsNeededForBonusLife = PointsFor.EatingFirstGhost;

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.EatPill();

            var previousLives = gameHarness.Lives;

            using var _ = new AssertionScope();
            await gameHarness.AssertSingleNotificationFires(GameNotification.ExtraPac, async() =>
            {
                await gameHarness.EatGhost(ghost);
            });

            gameHarness.Game.Lives.Should().Be(previousLives + 1);
        }
Ejemplo n.º 7
0
        public async Task WeGetAnExtraLifeWhenScoreReachesBonusLifePointAfterEatingFruit()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.Coins.Add(gameSettings.PacMan.Location.Below);
            gameSettings.Coins.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.Fruit = gameSettings.PacMan.Location.Below.Below;
            gameSettings.FruitAppearsAfterCoinsEaten.Add(1);
            gameSettings.PointsNeededForBonusLife = PointsFor.EatingFirstFruit;

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Down);

            var previousLives = gameHarness.Lives;

            await gameHarness.EatCoin();

            gameHarness.WeExpectThatPacMan().HasLives(previousLives);

            using var _ = new AssertionScope();
            await gameHarness.AssertSingleNotificationFires(GameNotification.ExtraPac, async() =>
            {
                await gameHarness.EatFruit();
            });

            gameHarness.Game.Lives.Should().Be(previousLives + 1);
        }
Ejemplo n.º 8
0
        public async Task TheHighScoreAlwaysIncrementsAfterEatingAGhostDuringTheFirstGame()
        {
            var gameSettings = new TestGameSettings();

            var ghostStart = gameSettings.PacMan.Location.Left.Left.Left;
            var ghost      = GhostBuilder.New()
                             .WithLocation(ghostStart)
                             .WithChaseStrategyRight()
                             .WithScatterStrategyRight()
                             .Create();

            gameSettings.Ghosts.Add(ghost);
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.Left);

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            gameHarness.WeExpectThatPacMan().IsAt(gameSettings.PacMan.Location);
            gameHarness.WeExpectThatGhost(ghost).IsAt(gameSettings.PacMan.Location.Left.Left.Left);

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.EatPill();

            gameHarness.WeExpectThatPacMan().IsAt(gameSettings.PacMan.Location.Left);
            gameHarness.WeExpectThatGhost(ghost).IsAt(gameSettings.PacMan.Location.Left.Left);

            await gameHarness.EatGhost(ghost);

            gameHarness.Game.HighScore.Should().Be(gameHarness.Score);
        }
Ejemplo n.º 9
0
        public FruitTests()
        {
            _now = DateTime.UtcNow;

            _gameSettings = new TestGameSettings();
            _gameClock    = new TestGameClock();
        }
Ejemplo n.º 10
0
        private Game CreateInitialGameSettings(Action <TestGameSettings> configure)
        {
            var gameSettings = new TestGameSettings
            {
                PointsNeededForBonusLife = 5
            };

            configure(gameSettings);

            return(new Game(_gameClock, gameSettings)
                   .Subscribe(GameNotification.ExtraPac, () => _numberOfNotificationsTriggered++));
        }
Ejemplo n.º 11
0
        public async Task TheHighScoreAlwaysIncrementsAfterEatingAPowerPillDuringTheFirstGame()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.Below);
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.FarAway());

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatPill();

            gameHarness.Game.HighScore.Should().Be(gameHarness.Score);
        }
Ejemplo n.º 12
0
        public async Task TheNewHighScoreGetsSavedWhenTheGameEnds()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.HighScoreStorage = this;
            gameSettings.InitialLives     = 1;

            var ghostStart = gameSettings.PacMan.Location.Left.Left.Left;
            var ghost      = GhostBuilder.New()
                             .WithLocation(ghostStart)
                             .WithChaseStrategyRight()
                             .WithScatterStrategyRight()
                             .Create();

            gameSettings.Ghosts.Add(ghost);
            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.Coins.Add(gameSettings.PacMan.Location.Left);

            var gameHarness = new GameHarness(gameSettings);

            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Left);

            if (gameHarness.Game.HighScore != 0)
            {
                throw new Exception($"The current high score should be 0 not {gameHarness.Game.HighScore}.");
            }

            await gameHarness.EatCoin();

            var newHighScore = gameHarness.Game.HighScore;

            await gameHarness.GetEatenByGhost(ghost);

            if (newHighScore != gameHarness.Score)
            {
                throw new Exception($"The current high score should be {newHighScore} not {gameHarness.Game.HighScore}.");
            }

            await gameHarness.WaitAndEnterAttractMode();

            _highScoresSet.Should().BeEquivalentTo(new[] { newHighScore });
        }
Ejemplo n.º 13
0
        public async Task GameContainsAllCoins()
        {
            var gameBoard = new TestGameSettings();

            gameBoard.Coins.Add((1, 1));
            gameBoard.Coins.Add((1, 2));
            gameBoard.Coins.Add((2, 2));

            var gameClock = new TestGameClock();
            var game      = new Game(gameClock, gameBoard);

            game.StartGame();
            await gameClock.Tick();

            game.Coins.Should().BeEquivalentTo(
                new CellLocation(1, 1),
                new CellLocation(1, 2),
                new CellLocation(2, 2)
                );
        }
Ejemplo n.º 14
0
        public async Task TheHighScoreAlwaysIncrementsAfterEatingFruitDuringTheFirstGame()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.Coins.Add(gameSettings.PacMan.Location.Below);
            gameSettings.Coins.Add(gameSettings.PacMan.Location.FarAway());
            gameSettings.Fruit = gameSettings.PacMan.Location.Below.Below;
            gameSettings.FruitAppearsAfterCoinsEaten.Add(1);

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatCoin();

            await gameHarness.EatFruit();

            gameHarness.Game.HighScore.Should().Be(gameHarness.Score);
        }
Ejemplo n.º 15
0
        public async Task WeGetAnExtraLifeWhenScoreReachesBonusLifePointAfterEatingPowerPillThatCompletesLevel()
        {
            var gameSettings = new TestGameSettings();

            gameSettings.PowerPills.Add(gameSettings.PacMan.Location.Below);
            gameSettings.PointsNeededForBonusLife = PointsFor.EatingPowerPill;

            var gameHarness = new GameHarness(gameSettings);
            await gameHarness.PlayGame();

            var previousLives = gameHarness.Lives;

            await gameHarness.ChangeDirection(Direction.Down);

            using var _ = new AssertionScope();
            await gameHarness.AssertSingleNotificationFires(GameNotification.ExtraPac, async() =>
            {
                await gameHarness.EatPill();
            });

            gameHarness.Game.Lives.Should().Be(previousLives + 1);
        }
Ejemplo n.º 16
0
 public FruitTests()
 {
     _gameSettings = new TestGameSettings();
 }
Ejemplo n.º 17
0
 public CoinTests()
 {
     _gameSettings = new TestGameSettings();
     _gameClock    = new TestGameClock();
 }
Ejemplo n.º 18
0
 public PacManTests()
 {
     _gameSettings = new TestGameSettings();
 }
Ejemplo n.º 19
0
 public PowerPillTests()
 {
     _gameSettings = new TestGameSettings();
     _gameClock    = new TestGameClock();
 }
Ejemplo n.º 20
0
 public LivesTests()
 {
     _gameSettings = new TestGameSettings();
     _gameClock    = new TestGameClock();
 }
Ejemplo n.º 21
0
 public CoinTests()
 {
     _gameSettings = new TestGameSettings();
 }
Ejemplo n.º 22
0
 public GameTests()
 {
     _gameSettings = new TestGameSettings();
 }
Ejemplo n.º 23
0
 public GhostTests()
 {
     _gameSettings = new TestGameSettings();
     _gameClock    = new TestGameClock();
 }
Ejemplo n.º 24
0
 public PacManTests()
 {
     _gameSettings = new TestGameSettings();
     _gameClock    = new TestGameClock();
 }
Ejemplo n.º 25
0
 public LivesTests()
 {
     _gameSettings = new TestGameSettings();
 }