private async Task MoveGhosts(BehaviorContext <GameState, Tick> context, GameStateMachine gameStateMachine) { ApplyToGhosts(ghost => ghost.Move(this)); if (TryHasDied(out var ghost)) { await context.Raise(gameStateMachine.GhostCollision, new GhostCollision(ghost !)); } }
public Game(IGameClock gameClock, IGameSettings settings) { _gameClock = gameClock; _settings = settings; PacMan = settings.PacMan; _collectedCoins = new List <CellLocation>(); _collectedPowerPills = new List <CellLocation>(); _ghosts = settings.Ghosts.ToDictionary(x => x.Name, x => x); _gameStateMachine = new GameStateMachine(this, settings, _gameNotifications); _gameState = new GameState(settings); }
public Game(IGameClock gameClock, IGameSettings settings) { _gameClock = gameClock; _settings = settings; _gameStateMachine = new GameStateMachine(settings, _gameNotifications, this); var gameState = new GameState(settings); _gameState = gameState; _gameStateMachineInstance = _gameStateMachine.CreateInstanceLift(gameState); Walls = _settings.Walls.Union(_settings.Doors).ToList().AsReadOnly(); _fruitForLevel = new[] { new Fruit(_settings.Fruit, FruitType.Cherry) }; }
public Game(IGameClock gameClock, IGameSettings settings) { _gameClock = gameClock; _settings = settings; var actions = new Actions(settings, _gameNotifications); _gameStateMachine = new GameStateMachine(actions, settings, this); var gameState = new GameState(settings); _gameState = gameState; _gameStateMachineInstance = _gameStateMachine.CreateInstanceLift(gameState); WallsAndDoors = _settings.Walls.Union(_settings.Doors).ToList().AsReadOnly(); Walls = _settings.Walls; _fruitForLevel = new[] { new Fruit(_settings.Fruit, FruitType.Cherry) }; GhostHouseMiddle = CalculateMiddleOfGhostHouse(settings.GhostHouse); }
internal async Task MoveGhosts(Game game, GameState gameState, BehaviorContext<GameState, Tick> context, GameStateMachine gameStateMachine) { gameState.ApplyToGhosts(ghost => ghost.Move(game, gameState)); var ghosts = GhostsCollidedWithPacMan(gameState); foreach (var ghost in ghosts) { await context.Raise(gameStateMachine.GhostCollision, new GhostCollision(ghost)); } }
internal async Task MovePacMan(Game game, GameState gameState, BehaviorContext<GameState, Tick> context, GameStateMachine gameStateMachine) { var newPacManLocation = gameState.PacMan.Location + gameState.PacMan.Direction; if (game.Portals.TryGetValue(newPacManLocation, out var otherEndOfThePortal)) { newPacManLocation = otherEndOfThePortal + gameState.PacMan.Direction; } if (!game.Walls.Contains(newPacManLocation)) { gameState.MovePacManTo(newPacManLocation); } var ghosts = GhostsCollidedWithPacMan(gameState); foreach (var ghost in ghosts) { await context.Raise(gameStateMachine.GhostCollision, new GhostCollision(ghost)); } if (gameState.RemainingCoins.Contains(newPacManLocation)) { await context.Raise(gameStateMachine.CoinCollision, new CoinCollision(newPacManLocation)); } if (gameState.RemainingPowerPills.Contains(newPacManLocation)) { await context.Raise(gameStateMachine.PowerPillCollision, new PowerPillCollision(newPacManLocation)); } if (_gameSettings.Fruit == newPacManLocation && gameState.FruitVisible ) { await context.Raise(gameStateMachine.FruitCollision, new FruitCollision(newPacManLocation)); } }
internal async Task MoveGhosts(Game game, GameState gameState, BehaviorContext <GameState, Tick> context, GameStateMachine gameStateMachine) { var coinsRemaining = game.Coins.Count; var ghostsToMove = game.Ghosts.Values.Where(ghost => _gameSettings.MoveClock.ShouldGhostMove(game.Level, coinsRemaining, ghost.Name, ghost.Status, inTunnel: _gameSettings.Tunnels.Contains(ghost.Location))); gameState.ApplyToGhosts(ghost => ghost.Move(game, gameState), ghostsToMove); var ghosts = GhostsCollidedWithPacMan(gameState); foreach (var ghost in ghosts) { await context.Raise(gameStateMachine.GhostCollision, new GhostCollision(ghost)); } }
async Task IGameActions.MovePacMan(BehaviorContext <GameState, Tick> context, GameStateMachine gameStateMachine) { var newPacMan = PacMan.Move(); if (_settings.Portals.TryGetValue(newPacMan.Location, out var portal)) { newPacMan = PacMan.WithNewX(portal.X).WithNewY(portal.Y); newPacMan = newPacMan.Move(); } if (!_settings.Walls.Contains(newPacMan.Location)) { PacMan = newPacMan; } var died = false; if (TryHasDied(out var ghost)) { died = !ghost !.Edible; await context.Raise(gameStateMachine.GhostCollision, new GhostCollision(ghost)); } if (!died && Coins.Contains(newPacMan.Location)) { var newCollectedCoins = new List <CellLocation>(_collectedCoins) { (newPacMan.Location) }; _collectedCoins = newCollectedCoins; await context.Raise(gameStateMachine.CoinEaten); } else if (!died && PowerPills.Contains(newPacMan.Location)) { var newCollectedPowerPills = new List <CellLocation>(_collectedPowerPills) { (newPacMan.Location) }; _collectedPowerPills = newCollectedPowerPills; await context.Raise(gameStateMachine.PowerPillEaten); } }
Task IGameActions.MoveGhosts(BehaviorContext <GameState, Tick> context, GameStateMachine gameStateMachine) { return(MoveGhosts(context, gameStateMachine)); }