Exemplo n.º 1
0
        public async Task CannotCollectTheSameCoinTwice()
        {
            var pacManStartingLocation = _gameSettings.PacMan.Location;

            _gameSettings.Coins.Add(pacManStartingLocation.Below);
            _gameSettings.Coins.Add(pacManStartingLocation.FarAway());

            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatCoin();

            await gameHarness.ChangeDirection(Direction.Up);

            await gameHarness.Move();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.Move();

            gameHarness.Score.Should().Be(10);
        }
Exemplo n.º 2
0
        public async Task PacManShouldBeAliveAfter4SecondsWhenInRespawning()
        {
            var initialPosition = _gameSettings.PacMan.Location;

            var ghost = GhostBuilder.New()
                        .WithLocation(initialPosition.Left.Left.Left.Left)
                        .WithScatterStrategyRight()
                        .WithChaseStrategyRight()
                        .Create();

            _gameSettings.Ghosts.Add(ghost);

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

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.Move();

            await gameHarness.GetEatenByGhost(ghost);

            await gameHarness.WaitToFinishDying();

            gameHarness.EnsureGameStatus(GameStatus.Respawning);

            await gameHarness.WaitToRespawn();

            gameHarness.Game.Status.Should().Be(GameStatus.Alive);
        }
Exemplo n.º 3
0
        public async Task ShouldNotWalkVerticallyInToWalls()
        {
            var wallLocation       = _gameSettings.PacMan.Location.Below;
            var ghostStartLocation = _gameSettings.PacMan.Location.Below.Below;

            _gameSettings.Walls.Add(wallLocation);
            var ghost = _ghostBuilder.WithLocation(ghostStartLocation).Create();

            _gameSettings.Ghosts.Add(ghost);

            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();
            await gameHarness.Move();

            using var _ = new AssertionScope();
            gameHarness.Game.Ghosts[ghost.Name].Should().NotBeEquivalentTo(new
            {
                Location = wallLocation
            });

            gameHarness.Game.Ghosts[ghost.Name].Should().NotBeEquivalentTo(new
            {
                Location = ghostStartLocation
            });
        }
Exemplo n.º 4
0
        public async Task LivesDecreaseWhenCollidesWithGhostWalkingTowardsPacMan()
        {
            // G . . . P
            // . G . P .
            // . . PG . .
            var ghost = GhostBuilder.New()
                        .WithLocation(_gameSettings.PacMan.Location.Left.Left.Left.Left)
                        .WithChaseStrategyRight()
                        .WithScatterStrategyRight()
                        .Create();

            _gameSettings.Ghosts.Add(ghost);

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

            var currentLives = gameHarness.Lives;

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.Move();

            await gameHarness.GetEatenByGhost(ghost);

            gameHarness.Lives.Should().Be(currentLives - 1);
        }
Exemplo n.º 5
0
        public async Task TheGameResumesAfterBeingPausedForOneSecondAfterGhostIsEaten()
        {
            //      P
            //   .  *
            // G .  .

            var ghostStart1 = _gameSettings.PacMan.Location.Below.Below.Left.Left;
            var ghost1      = GhostBuilder.New()
                              .WithLocation(ghostStart1)
                              .WithChaseStrategyRight()
                              .Create();
            var ghost2 = GhostBuilder.New()
                         .WithLocation(_gameSettings.PacMan.Location.FarAway())
                         .WithChaseStrategyRight()
                         .Create();

            _gameSettings.Ghosts.Add(ghost1);
            _gameSettings.Ghosts.Add(ghost2);

            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Below);


            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.Game.StartGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatPill();

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below);
            gameHarness.WeExpectThatGhost(ghost1).IsAt(ghostStart1.Right);

            await gameHarness.EatGhost(ghost1);

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below.Below);

            var pacManLocation = gameHarness.Game.PacMan.Location;
            var ghostLocations = gameHarness.Game.Ghosts.Values.Select(x => new {
                x.Name,
                x.Location
            }).ToDictionary(x => x.Name);

            await gameHarness.WaitForPauseToComplete();

            await gameHarness.Move();

            using var _ = new AssertionScope();
            gameHarness.Game.PacMan.Should().NotBeEquivalentTo(new
            {
                Location = pacManLocation
            });
            gameHarness.Game.Ghosts.Should().NotBeEmpty();
            gameHarness.Game.Ghosts.Should().NotBeEquivalentTo(ghostLocations);
        }
Exemplo n.º 6
0
        public async Task CannotCollectTheSamePowerPillTwice()
        {
            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.FarAway());
            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Below);
            var gameHarness = new GameHarness(_gameSettings);
            await gameHarness.PlayGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatPill();

            await gameHarness.ChangeDirection(Direction.Up);

            await gameHarness.Move();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.Move();

            gameHarness.Score.Should().Be(50);
        }
Exemplo n.º 7
0
        public async Task ShouldTurnAtCorner()
        {
            // X X X X
            // X ^ ▶ ▶ C
            // X S X X

            var topLeft = new CellLocation();

            _gameSettings.Walls.Add(topLeft);
            _gameSettings.Walls.Add(topLeft.Right);
            _gameSettings.Walls.Add(topLeft.Right.Right);
            _gameSettings.Walls.Add(topLeft.Right.Right.Right);
            _gameSettings.Walls.Add(topLeft.Below);
            _gameSettings.Walls.Add(topLeft.Below.Below);
            _gameSettings.Walls.Add(topLeft.Below.Below.Right.Right);
            _gameSettings.Walls.Add(topLeft.Below.Below.Right.Right.Right);

            var ghost = _ghostBuilder.WithLocation(topLeft.Below.Below.Right)
                        .WithDirection(Direction.Up).Create();

            _gameSettings.Ghosts.Add(ghost);

            _gameSettings.PacMan = new PacMan(topLeft.Below.Right.Right.Right.Right, Direction.Right);

            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();
            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            using var _ = new AssertionScope();
            gameHarness.Game.Ghosts[ghost.Name].Should().BeEquivalentTo(new
            {
                Location  = topLeft.Below.Right.Right.Right,
                Direction = Direction.Right
            });
        }
Exemplo n.º 8
0
        public async Task ScoreDoesNotChangeWhenNoCoinIsCollected()
        {
            var gameHarness = new GameHarness(_gameSettings);
            await gameHarness.PlayGame();

            var score = gameHarness.Score;

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.Move();

            gameHarness.Score.Should().Be(score);
        }
Exemplo n.º 9
0
        public async Task GhostShouldBeRunningHomeAfterThePauseAfterBeingTheEaten()
        {
            //      P
            //   .  *
            // G .  .

            var ghostStart1 = _gameSettings.PacMan.Location.Below.Below.Left.Left;
            var ghost1      = GhostBuilder.New()
                              .WithLocation(ghostStart1)
                              .WithChaseStrategyRight()
                              .Create();
            var ghost2 = GhostBuilder.New()
                         .WithLocation(_gameSettings.PacMan.Location.FarAway())
                         .WithChaseStrategyRight()
                         .Create();

            _gameSettings.Ghosts.Add(ghost1);
            _gameSettings.Ghosts.Add(ghost2);

            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Below);


            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.Game.StartGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatPill();

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below);
            gameHarness.WeExpectThatGhost(ghost1).IsAt(ghostStart1.Right);

            await gameHarness.EatGhost(ghost1);

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below.Below);

            var pacManLocation = gameHarness.Game.PacMan.Location;
            var ghostLocations = gameHarness.Game.Ghosts.Values.Select(x => new {
                x.Name,
                x.Location
            }).ToDictionary(x => x.Name);

            await gameHarness.WaitForPauseToComplete();

            await gameHarness.Move();

            using var _ = new AssertionScope();
            gameHarness.Game.Ghosts[ghost1.Name].Status.Should().Be(GhostStatus.RunningHome);
            gameHarness.Game.Ghosts[ghost2.Name].Status.Should().Be(GhostStatus.Edible);
        }
Exemplo n.º 10
0
        public async Task PacManWalksInFacingDirection(Direction directionToFace)
        {
            var initialPosition = _gameSettings.PacMan.Location;

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

            await gameHarness.ChangeDirection(directionToFace);

            await gameHarness.Move();

            gameHarness.Game.PacMan.Should().BeEquivalentTo(new
            {
                Location  = initialPosition + directionToFace,
                Direction = directionToFace
            });
        }
Exemplo n.º 11
0
        public async Task LivesStayTheSameWhenNotCollidingWithAGhost()
        {
            var ghost = GhostBuilder.New().WithLocation(_gameSettings.PacMan.Location.Right).Create();

            _gameSettings.Ghosts.Add(ghost);

            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();
            var currentLives = gameHarness.Lives;

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.Move();

            gameHarness.Lives.Should().Be(currentLives);
        }
Exemplo n.º 12
0
        public async Task ShouldMoveTowardsPacMan(int pacManX, int pacManY, int expectedGhostPositionX, int expectedGhostPositionY)
        {
            var ghost = _ghostBuilder.WithLocation((5, 5)).Create();

            _gameSettings.Ghosts.Add(ghost);
            _gameSettings.PacMan = new PacMan((pacManX, pacManY), Direction.Left);

            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();
            await gameHarness.Move();

            gameHarness.Game.Ghosts[ghost.Name].Should().BeEquivalentTo(new
            {
                Location = new
                {
                    X = expectedGhostPositionX,
                    Y = expectedGhostPositionY
                }
            });
        }
Exemplo n.º 13
0
        public async Task GameContainsAllCoins()
        {
            var coin1 = _gameSettings.PacMan.Location.FarAway().Left;
            var coin2 = _gameSettings.PacMan.Location.FarAway();
            var coin3 = _gameSettings.PacMan.Location.FarAway().Right;

            _gameSettings.Coins.Add(coin1);
            _gameSettings.Coins.Add(coin2);
            _gameSettings.Coins.Add(coin3);

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

            await gameHarness.Move();

            gameHarness.Game.Coins.Should().BeEquivalentTo(
                coin1,
                coin2,
                coin3
                );
        }
Exemplo n.º 14
0
        public async Task GameContainsAllPowerPills()
        {
            var powerPill1 = _gameSettings.PacMan.Location.FarAway().Left;
            var powerPill2 = _gameSettings.PacMan.Location.FarAway();
            var powerPill3 = _gameSettings.PacMan.Location.FarAway().Right;

            _gameSettings.PowerPills.Add(powerPill1);
            _gameSettings.PowerPills.Add(powerPill2);
            _gameSettings.PowerPills.Add(powerPill3);

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

            await gameHarness.Move();

            gameHarness.Game.PowerPills.Should().BeEquivalentTo(
                powerPill1,
                powerPill2,
                powerPill3
                );
        }
Exemplo n.º 15
0
        public async Task PacManIsTeleportedWhenYouWalkIntoAPortal()
        {
            var initialPosition = _gameSettings.PacMan.Location;

            var farEndOfPortal = new CellLocation(14, 15);
            var portalExit     = farEndOfPortal.Left;

            _gameSettings.Portals.Add(initialPosition.Left, farEndOfPortal);

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

            await gameHarness.ChangeDirection(Direction.Left);

            await gameHarness.Move();

            gameHarness.Game.PacMan.Should().BeEquivalentTo(new
            {
                Location  = portalExit,
                Direction = Direction.Left
            });
        }
Exemplo n.º 16
0
        public async Task GhostsShouldBeNotEdibleAfterPacManComesBackToLife()
        {
            //     G
            // > .   #       G
            //     -
            //     H
            var ghost1 = GhostBuilder.New()
                         .WithLocation(_gameSettings.PacMan.Location.Right.Right.Above)
                         .Create();
            var ghost2 = GhostBuilder.New()
                         .WithLocation(_gameSettings.PacMan.Location.FarAway())
                         .Create();
            var directionPicker = new TestDirectionPicker()
            {
                DefaultDirection = Direction.Down
            };

            _gameSettings.DirectionPicker = directionPicker;
            _gameSettings.Ghosts.Add(ghost1);
            _gameSettings.Ghosts.Add(ghost2);
            _gameSettings.Walls.Add(_gameSettings.PacMan.Location.Right.Right.Right);
            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Right);
            _gameSettings.Doors.Add(ghost1.Location.Below.Below);
            _gameSettings.GhostHouse.Add(_gameSettings.Doors.First().Below);

            var now         = DateTime.UtcNow;
            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.StartGame();
            await gameHarness.ChangeDirection(Direction.Right);

            await gameHarness.EatPill();

            gameHarness.WeExpectThatGhost(ghost1).IsEdible();
            gameHarness.WeExpectThatGhost(ghost2).IsEdible();

            await gameHarness.EatGhost(ghost1);

            gameHarness.WeExpectThatGhost(ghost1).IsNotEdible();
            gameHarness.WeExpectThatGhost(ghost2).IsEdible();

            await gameHarness.WaitForPauseToComplete();

            // Move to Ghost House
            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.GetEatenByGhost(ghost1);

            gameHarness.EnsureGameStatus(GameStatus.Dying);

            await gameHarness.WaitToFinishDying();

            gameHarness.EnsureGameStatus(GameStatus.Respawning);

            await gameHarness.WaitToRespawn();

            gameHarness.EnsureGameStatus(GameStatus.Alive);

            gameHarness.Game.Ghosts.Values.Should().AllBeEquivalentTo(new
            {
                Edible = false
            });
        }
Exemplo n.º 17
0
        public async Task GhostShouldBeInTheHouseAfterBeingEatingAndWaitingForElapsedTime()
        {
            //      P
            //   .  *   # - - #
            // G .  .   # H H #
            //          # # # #
            var ghostStart1 = _gameSettings.PacMan.Location.Below.Below.Left.Left;
            var ghost1      = GhostBuilder.New()
                              .WithLocation(ghostStart1)
                              .WithChaseStrategyRight()
                              .Create();

            var topLeftWall = _gameSettings.PacMan.Location.Right.Right.Below;

            _gameSettings.Walls.Add(topLeftWall);
            _gameSettings.Walls.Add(topLeftWall.Below);
            _gameSettings.Walls.Add(topLeftWall.Below.Below);
            _gameSettings.Walls.Add(topLeftWall.Below.Below.Right);
            _gameSettings.Walls.Add(topLeftWall.Below.Below.Right.Right);
            _gameSettings.Walls.Add(topLeftWall.Below.Below.Right.Right.Right);
            _gameSettings.Walls.Add(topLeftWall.Below.Right.Right.Right);
            _gameSettings.Walls.Add(topLeftWall.Right.Right.Right);

            _gameSettings.Doors.Add(topLeftWall.Right);
            _gameSettings.Doors.Add(topLeftWall.Right.Right);

            var ghostHouse = topLeftWall.Below.Right;

            _gameSettings.GhostHouse.Add(ghostHouse);
            _gameSettings.GhostHouse.Add(topLeftWall.Below.Right.Right);

            _gameSettings.Ghosts.Add(ghost1);

            _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Below);


            var gameHarness = new GameHarness(_gameSettings);

            gameHarness.Game.StartGame();

            await gameHarness.ChangeDirection(Direction.Down);

            await gameHarness.EatPill();

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below);
            gameHarness.WeExpectThatGhost(ghost1).IsAt(ghostStart1.Right);

            await gameHarness.EatGhost(ghost1);

            gameHarness.WeExpectThatPacMan().IsAt(_gameSettings.PacMan.Location.Below.Below);

            await gameHarness.WaitForPauseToComplete();

            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            await gameHarness.Move();

            gameHarness.WeExpectThatGhost(ghost1).IsAt(topLeftWall.Right);
            await gameHarness.Move();

            using var _ = new AssertionScope();
            gameHarness.Game.Ghosts[ghost1.Name].Status.Should().Be(GhostStatus.Alive);
            gameHarness.Game.Ghosts[ghost1.Name].Location.Should().Be(ghostHouse);
        }