public async Task GhostShouldScatterToStartWith() { _gameSettings.InitialGameStatus = GameStatus.Initial; _gameSettings.PacMan = new PacMan((10, 10), Direction.Left); var startingLocation = new CellLocation(3, 1); var scatterLocation = new CellLocation(1, 1); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", startingLocation, Direction.Right, scatterLocation, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); await _gameClock.Tick(); await _gameClock.Tick(); await _gameClock.Tick(); game.Ghosts.Values.First() .Should().BeEquivalentTo(new { Location = new { X = scatterLocation.X, Y = scatterLocation.Y } }); }
public async Task GhostShouldScatter7SecondsAfterChase() { _gameSettings.InitialGameStatus = GameStatus.Initial; _gameSettings.PacMan = new PacMan((29, 10), Direction.Left); var startingLocation = new CellLocation(30, 1); var scatterLocation = new CellLocation(1, 1); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", startingLocation, Direction.Right, scatterLocation, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); var now = DateTime.UtcNow; await _gameClock.Tick(now); WeExpectThat(ourGhost()).IsAt(startingLocation); await _gameClock.Tick(now); WeExpectThat(ourGhost()).IsAt(startingLocation.Left); await _gameClock.Tick(now.AddSeconds(_gameSettings.InitialScatterTimeInSeconds + 1)); WeExpectThat(ourGhost()).IsAt(startingLocation.Left.Right); await _gameClock.Tick(now.AddSeconds(_gameSettings.InitialScatterTimeInSeconds + 2)); WeExpectThat(ourGhost()).IsAt(startingLocation.Left.Right.Right); now = now.AddSeconds(_gameSettings.InitialScatterTimeInSeconds); await _gameClock.Tick(now.AddSeconds(_gameSettings.ChaseTimeInSeconds + 1)); WeExpectThat(ourGhost()).IsAt(startingLocation.Left.Right.Right.Left); await _gameClock.Tick(now.AddSeconds(_gameSettings.ChaseTimeInSeconds + 2)); ourGhost() .Should().BeEquivalentTo(new { Location = new { X = 29, Y = 1 } }); Ghost ourGhost() => game.Ghosts.Values.First(); }
public async Task GhostShouldBeHiddenWhenPacManIsReSpawning() { _gameSettings.PacMan = new PacMan((3, 2), Direction.Left); var homeLocation = new CellLocation(1, 2); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", homeLocation, Direction.Right, CellLocation.TopLeft, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); var now = DateTime.UtcNow; await _gameClock.Tick(now); await _gameClock.Tick(now.AddSeconds(4)); game.Ghosts.Should().BeEmpty(); }
public async Task GhostMovesInDirectionOfStrategy() { var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", new CellLocation(0, 0), Direction.Left, CellLocation.TopLeft, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); await _gameClock.Tick(); game.Ghosts["Ghost1"].Should().BeEquivalentTo(new { Location = new { X = 1, Y = 0 } }); }
public async Task GhostShouldBeBackAtHomeAfterPacManDiesAndComesBackToLife() { _gameSettings.PacMan = new PacMan((3, 2), Direction.Left); var homeLocation = new CellLocation(1, 2); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", homeLocation, Direction.Right, CellLocation.TopLeft, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); var now = DateTime.UtcNow; await _gameClock.Tick(now); 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.First() .Should().BeEquivalentTo(new { Location = new { X = homeLocation.X, Y = homeLocation.Y } }); }
public async Task GhostShouldChaseAfter7Seconds() { _gameSettings.InitialGameStatus = GameStatus.Initial; _gameSettings.PacMan = new PacMan((29, 10), Direction.Left); var startingLocation = new CellLocation(30, 1); var scatterLocation = new CellLocation(1, 1); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", startingLocation, Direction.Right, scatterLocation, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); var now = DateTime.UtcNow; await _gameClock.Tick(now); await _gameClock.Tick(now); if (game.Ghosts.Values.First().Location.X != 29 || game.Ghosts.Values.First().Location.Y != 1) { throw new System.Exception($"Ghost should be at 29,1 not {game.Ghosts.Values.First().Location.X}, {game.Ghosts.Values.First().Location.Y}"); } await _gameClock.Tick(now.AddSeconds(_gameSettings.InitialScatterTimeInSeconds + 1)); await _gameClock.Tick(now.AddSeconds(_gameSettings.InitialScatterTimeInSeconds + 2)); game.Ghosts.Values.First() .Should().BeEquivalentTo(new { Location = new { X = 31, Y = scatterLocation.Y } }); }