public async Task GhostsShouldBeInScatterModeAfterPacManComesBackToLife() { // G // > . var ghost = GhostBuilder.New() .WithLocation(_gameSettings.PacMan.Location.Right.Above) .WithScatterTarget(_gameSettings.PacMan.Location.Right.Above.Above) .Create(); var directionPicker = new TestDirectionPicker() { DefaultDirection = Direction.Down }; _gameSettings.DirectionPicker = directionPicker; _gameSettings.Ghosts.Add(ghost); var now = DateTime.UtcNow; var game = new Game(_gameClock, _gameSettings); game.StartGame(); await game.ChangeDirection(Direction.Right); await _gameClock.Tick(now); await game.ChangeDirection(Direction.Up); await _gameClock.Tick(now); //Now dead if (game.Status != GameStatus.Dying) { throw new Exception($"Invalid Game State {game.Status:G} Should be Dying"); } await _gameClock.Tick(now.AddSeconds(4)); if (game.Status != GameStatus.Respawning) { throw new Exception($"Invalid Game State {game.Status:G} Should be Respawning"); } await _gameClock.Tick(now.AddSeconds(8)); if (game.Status != GameStatus.Alive) { throw new Exception($"Invalid Game State {game.Status:G} Should be Alive"); } await _gameClock.Tick(now.AddSeconds(9)); game.Ghosts.Values.Should().AllBeEquivalentTo(new { Edible = false, Location = _gameSettings.PacMan.Location.Right.Above.Above }); }
public async Task GhostMovesRandomlyWhileFrightened() { var testDirectionPicker = new TestDirectionPicker(); testDirectionPicker.DefaultDirection = Direction.Up; var allDirections = new[] { Direction.Down, Direction.Up, Direction.Right }; testDirectionPicker.Returns(allDirections, Direction.Right); _gameSettings.DirectionPicker = testDirectionPicker; var ghostStart1 = _gameSettings.PacMan.Location.FarAway(); var ghost1 = GhostBuilder.New() .WithLocation(ghostStart1) .Create(); _gameSettings.Ghosts.Add(ghost1); _gameSettings.PowerPills.Add(_gameSettings.PacMan.Location.Left); var game = new Game(_gameClock, _gameSettings); game.StartGame(); // PacMan Eat Pill await game.ChangeDirection(Direction.Left); await _gameClock.Tick(); await _gameClock.Tick(); await _gameClock.Tick(); await _gameClock.Tick(); await _gameClock.Tick(); using var _ = new AssertionScope(); game.Ghosts[ghost1.Name].Should().BeEquivalentTo(new { Location = ghostStart1.Right.Right }); }
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 }); }
public async Task GhostsShouldBeNotEdibleAfterPacManComesBackToLife() { // G // > . # G 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); var now = DateTime.UtcNow; var game = new Game(_gameClock, _gameSettings); game.StartGame(); // Eat PowerPill await _gameClock.Tick(now); WeExpectThat(game.Ghosts[ghost1.Name]).IsEdible(); WeExpectThat(game.Ghosts[ghost2.Name]).IsEdible(); var score = game.Score; await _gameClock.Tick(now); await _gameClock.Tick(now); WeExpectThat(game.Ghosts[ghost1.Name]).IsAt(_gameSettings.PacMan.Location.Right.Right.Above); if (score == game.Score) { throw new Exception("Score should increase as ghost is eaten"); } WeExpectThat(game.Ghosts[ghost1.Name]).IsNotEdible(); WeExpectThat(game.Ghosts[ghost2.Name]).IsEdible(); await game.ChangeDirection(Direction.Up); await _gameClock.Tick(now); if (game.Status != GameStatus.Dying) { throw new Exception($"Invalid Game State {game.Status:G} Should be Dying"); } await _gameClock.Tick(now.AddSeconds(4)); if (game.Status != GameStatus.Respawning) { throw new Exception($"Invalid Game State {game.Status:G} Should be Respawning"); } await _gameClock.Tick(now.AddSeconds(8)); if (game.Status != GameStatus.Alive) { throw new Exception($"Invalid Game State {game.Status:G} Should be Alive"); } game.Ghosts.Values.Should().AllBeEquivalentTo(new{ Edible = false }); }