internal void PowerPillEaten(GameState gameState, CellLocation powerPillLocation) { IncreaseScoreAndCheckForBonusLife(gameState, 50); _gameNotifications.Publish(GameNotification.EatPowerPill); MakeGhostsEdible(gameState); gameState.RemovePowerPill(powerPillLocation); }
public GameSettings( int width, int height, IReadOnlyCollection <CellLocation> walls, IReadOnlyCollection <CellLocation> coins, IReadOnlyCollection <CellLocation> powerPills, IReadOnlyDictionary <CellLocation, CellLocation> portals, PacMan pacMan, IReadOnlyCollection <Ghost> ghosts, IReadOnlyCollection <CellLocation> doors, IReadOnlyCollection <CellLocation> ghostHouse, CellLocation fruit) { Width = width; Height = height; Portals = portals; PacMan = pacMan; Ghosts = ghosts; Walls = walls; Coins = coins; PowerPills = powerPills; Doors = doors; GhostHouse = ghostHouse; Fruit = fruit; }
internal void FruitEaten(Game game, GameState gameState, CellLocation location) { var scoreIncrement = Fruits.FruitForLevel(gameState.Level).Score; IncreaseScoreAndCheckForBonusLife(gameState, scoreIncrement); gameState.HideFruit(); _gameNotifications.Publish(GameNotification.EatFruit); }
public Ghost(string name, CellLocation location, Direction direction, IGhostStrategy chaseStrategy, IGhostStrategy scatterStrategy, IGhostStrategy frightenedStrategy, int numberOfCoinsRequiredToExitHouse = 0) : this(name, location, location, direction, chaseStrategy, scatterStrategy, frightenedStrategy, chaseStrategy, GhostStatus.Alive, numberOfCoinsRequiredToExitHouse) { }
private Ghost(string name, CellLocation homeLocation, CellLocation currentLocation, Direction direction, CellLocation scatterTarget, IGhostStrategy strategy, IGhostStrategy currentStrategy, bool edible) { Name = name; Home = homeLocation; Location = currentLocation; Direction = direction; Strategy = strategy; CurrentStrategy = currentStrategy; ScatterTarget = scatterTarget; Edible = edible; }
internal void CoinEaten(Game game, GameState gameState, CellLocation coinLocation) { gameState.RemoveCoin(coinLocation); IncreaseScoreAndCheckForBonusLife(gameState, 10); if(_gameSettings.FruitAppearsAfterCoinsEaten.Contains(game.StartingCoins.Count - game.Coins.Count)) { var fruitType = Fruits.FruitForLevel(gameState.Level).FruitType; gameState.ShowFruit(_gameSettings.FruitVisibleForSeconds, fruitType); } _gameNotifications.Publish(GameNotification.EatCoin); }
private Ghost(string name, CellLocation homeLocation, CellLocation currentLocation, Direction direction, CellLocation scatterTarget, IGhostStrategy chaseStrategy, IGhostStrategy currentStrategy, GhostStatus ghostStatus, int numberOfCoinsRequiredToExitHouse) { Name = name; Home = homeLocation; Location = currentLocation; Direction = direction; ChaseStrategy = chaseStrategy; CurrentStrategy = currentStrategy; ScatterTarget = scatterTarget; Status = ghostStatus; NumberOfCoinsRequiredToExitHouse = numberOfCoinsRequiredToExitHouse; }
internal void MovePacManTo(CellLocation newPacManLocation) { PacMan = PacMan.WithNewLocation(newPacManLocation); }
private Ghost WithNewLocationAndDirection(CellLocation newLocation, Direction newDirection) => new Ghost(Name, Home, newLocation, newDirection, ScatterTarget, ChaseStrategy, CurrentStrategy, Status, NumberOfCoinsRequiredToExitHouse);
public PacMan(CellLocation location, Direction direction) : this(location, home : location, direction) { }
public static IGameSettings Load(string board) { var allRows = board.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var rows = allRows.Where(line => !line.StartsWith("{")).ToArray(); var instructions = allRows.Where(line => line.StartsWith("{")).ToArray(); var height = rows.Length; var width = 0; var homeLocations = FindHomeLocations(instructions); var coins = new List <CellLocation>(); var powerPills = new List <CellLocation>(); var walls = new List <CellLocation>(); var doors = new List <CellLocation>(); var portalParts = new List <CellLocation>(); var ghosts = new List <Ghost>(); PacMan?pacMan = null; for (int rowNumber = 0; rowNumber < height; rowNumber++) { var row = rows[rowNumber]; for (int columnNumber = 0; columnNumber < row.Length; columnNumber++) { var location = new CellLocation(columnNumber - 1, rowNumber); switch (row[columnNumber]) { case 'B': var homeB = homeLocations[GhostNames.Blinky]; ghosts.Add(new Ghost(GhostNames.Blinky, location, Direction.Left, new CellLocation(homeB.X, homeB.Y), new DirectToStrategy(new DirectToPacManLocation()))); break; case 'P': var homeP = homeLocations[GhostNames.Pinky]; ghosts.Add(new Ghost(GhostNames.Pinky, location, Direction.Left, new CellLocation(homeP.X, homeP.Y), new DirectToStrategy(new DirectToExpectedPacManLocation()))); break; case 'I': var homeI = homeLocations[GhostNames.Inky]; ghosts.Add(new Ghost(GhostNames.Inky, location, Direction.Left, new CellLocation(homeI.X, homeI.Y), new DirectToStrategy(new InterceptPacManLocation(GhostNames.Blinky)))); break; case 'C': var homeC = homeLocations[GhostNames.Clyde]; ghosts.Add(new Ghost(GhostNames.Clyde, location, Direction.Left, new CellLocation(homeC.X, homeC.Y), new DirectToStrategy(new StaysCloseToPacManLocation(GhostNames.Clyde)))); break; case '▲': pacMan = new PacMan(location, Direction.Up); break; case '▼': pacMan = new PacMan(location, Direction.Down); break; case '►': pacMan = new PacMan(location, Direction.Right); break; case '◄': pacMan = new PacMan(location, Direction.Left); break; case 'X': walls.Add(location); break; case '-': doors.Add(location); break; case 'T': portalParts.Add(location); break; case '.': coins.Add(location); break; case '*': powerPills.Add(location); break; default: break; } width = Math.Max(width, row.Length); } } if (portalParts.Count() != 0 && portalParts.Count() != 2) { throw new Exception("Unexpected number of portals"); } var portals = new Dictionary <CellLocation, CellLocation>(); if (portalParts.Any()) { portals.Add(portalParts[0], portalParts[1]); portals.Add(portalParts[1], portalParts[0]); } if (pacMan is null) { throw new Exception("Pacman seems to be missing from the board."); } return(new GameSettings(width - 2, height, walls, coins, powerPills, portals, pacMan, ghosts, doors)); }
public PacMan WithNewLocation(CellLocation newLocation) => new PacMan(newLocation, Direction);
private PacMan(CellLocation location, CellLocation home, Direction direction) { Location = location; Direction = direction; Home = home; }
public Ghost(string name, CellLocation location, Direction direction, CellLocation scatterTarget, IGhostStrategy chaseStrategy, int numberOfCoinsRequiredToExitHouse = 0) : this(name, location, location, direction, scatterTarget, chaseStrategy, chaseStrategy, false, numberOfCoinsRequiredToExitHouse) { }
public Ghost(string name, CellLocation location, Direction direction, CellLocation scatterTarget, IGhostStrategy strategy) : this(name, location, location, direction, scatterTarget, strategy, strategy, false) { }
public PacMan(CellLocation location, Direction direction) { Location = location; Direction = direction; }
internal void RemovePowerPill(CellLocation location) { // Note - this is not the same as gameState.RemainingPowerPills = gameState.RemainingPowerPills.Remove(location) // We have to allow for the UI to be iterating over the list whilst we are removing elements from it. RemainingPowerPills = RemainingPowerPills.Where(p => p != location).ToList(); }
public static void PowerPillEaten(IGameSettings gameSettings, GameState gameState, CellLocation powerPillLocation, GameNotifications gameNotifications) { gameState.IncreaseScore(50); gameNotifications.Publish(GameNotification.EatPowerPill); MakeGhostsEdible(gameSettings, gameState); gameState.RemovePowerPill(powerPillLocation); }
public static void CoinEaten(Game game, IGameSettings settings, GameState gameState, CellLocation coinLocation, GameNotifications gameNotifications) { gameState.RemoveCoin(coinLocation); gameState.IncreaseScore(10); if (settings.FruitAppearsAfterCoinsEaten.Contains(game.StartingCoins.Count - game.Coins.Count)) { if (!FruitForLevel.TryGetValue(gameState.Level, out var fruitType)) { fruitType = FruitType.Key; } gameState.ShowFruit(settings.FruitVisibleForSeconds, fruitType); } gameNotifications.Publish(GameNotification.EatCoin); }
internal static void FruitEaten(Game game, IGameSettings settings, GameState gameState, CellLocation location, GameNotifications gameNotifications) { var scoreInc = gameState.FruitTypeToShow switch { FruitType.Cherry => 100, FruitType.Strawberry => 300, FruitType.Orange => 500, FruitType.Bell => 700, FruitType.Apple => 1000, FruitType.Grapes => 2000, FruitType.Arcadian => 3000, FruitType.Key => 5000, _ => throw new NotImplementedException() }; gameState.IncreaseScore(scoreInc); gameState.HideFruit(); gameNotifications.Publish(GameNotification.EatFruit); }