Exemplo n.º 1
0
 public static void GhostEaten(GameState gameState, Ghost ghost, Game game, GameNotifications gameNotifications)
 {
     SendGhostHome(gameState, ghost);
     IncreaseScoreAfterEatingGhost(gameState, game);
     MakeGhostNotEdible(gameState, ghost);
     gameNotifications.Publish(GameNotification.EatGhost);
 }
Exemplo n.º 2
0
 public static void SetupGame(GameState gameState, DateTime now, GameNotifications gameNotifications)
 {
     gameState.RecordLastTick(now);
     MoveGhostsHome(gameState);
     gameState.ShowGhosts();
     gameNotifications.Publish(GameNotification.Beginning);
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 internal void Tick(GameState gameState, DateTime now)
 {
     _gameNotifications.Publish(GameNotification.PreTick);
     gameState.RecordLastTick(now);
 }
Exemplo n.º 7
0
        public GameStateMachine(IGameActions game, IGameSettings settings, GameNotifications gameNotifications)
        {
            InstanceState(x => x.Status);

            DuringAny(
                When(Tick)
                .Then(context => context.Instance.LastTick = context.Data.Now));

            Initially(
                When(Tick)
                .Then(context => context.Instance.LastTick = context.Data.Now)
                .Then(context => game.MoveGhostsHome())
                .Then(context => game.ShowGhosts(context.Instance))
                .Then(context => gameNotifications.Publish(GameNotification.Beginning))
                .TransitionTo(Scatter));

            WhenEnter(Scatter,
                      binder => binder
                      .Then(context => context.Instance.TimeToChangeState = context.Instance.LastTick.AddSeconds(settings.InitialScatterTimeInSeconds))
                      .Then(context => game.ScatterGhosts()));

            During(Scatter,
                   When(Tick, context => context.Data.Now >= context.Instance.TimeToChangeState)
                   .TransitionTo(GhostChase));

            WhenEnter(GhostChase,
                      binder => binder
                      .Then(context => context.Instance.TimeToChangeState = context.Instance.LastTick.AddSeconds(settings.ChaseTimeInSeconds))
                      .Then(context => game.GhostToChase()));

            During(GhostChase,
                   When(Tick, context => context.Data.Now >= context.Instance.TimeToChangeState)
                   .TransitionTo(Scatter));

            During(Frightened,
                   When(Tick, context => context.Data.Now >= context.Instance.TimeToChangeState)
                   .Then(x => game.MakeGhostsNotEdible())
                   .TransitionTo(Scatter));

            During(Scatter, GhostChase, Frightened,
                   When(Tick)
                   .ThenAsync(async context => await game.MoveGhosts(context, this))
                   .Then(context => game.MovePacMan(context, this)),
                   When(CoinEaten)
                   .Then(context => context.Instance.Score += 10)
                   .Then(context => gameNotifications.Publish(GameNotification.EatCoin)),
                   When(PowerPillEaten)
                   .Then(context => context.Instance.Score += 50)
                   .Then(context => gameNotifications.Publish(GameNotification.EatPowerPill))
                   .Then(context => game.MakeGhostsEdible())
                   .Then(context => context.Instance.TimeToChangeState = context.Instance.LastTick.AddSeconds(7))
                   .TransitionTo(Frightened),
                   When(GhostCollision)
                   .IfElse(x => x.Data.Ghost.Edible,
                           binder => binder.Then(x => game.SendGhostHome(x.Data.Ghost)),
                           binder => binder.Then(context => context.Instance.Lives -= 1)
                           .TransitionTo(Dying)));

            WhenEnter(Dying,
                      binder => binder
                      .Then(context => context.Instance.TimeToChangeState = context.Instance.LastTick.AddSeconds(4))
                      .Then(context => gameNotifications.Publish(GameNotification.Dying)));

            During(Dying,
                   When(Tick, context => context.Data.Now >= context.Instance.TimeToChangeState)
                   .Then(context => game.HideGhosts(context.Instance))
                   .Then(context => context.Instance.TimeToChangeState = context.Data.Now.AddSeconds(4))
                   .IfElse(context => context.Instance.Lives > 0,
                           binder => binder.TransitionTo(Respawning),
                           binder => binder.TransitionTo(Dead)));

            WhenEnter(Respawning,
                      binder => binder
                      .Then(context => gameNotifications.Publish(GameNotification.Respawning)));

            During(Respawning,
                   When(Tick, context => context.Data.Now >= context.Instance.TimeToChangeState)
                   .Then(context => context.Instance.TimeToChangeState = context.Data.Now.AddSeconds(4))
                   .Then(context => game.MoveGhostsHome())
                   .Then(context => game.MovePacManHome())
                   .Then(context => game.ShowGhosts(context.Instance))
                   .TransitionTo(GhostChase));

            During(Dead, Ignore(Tick));
        }
Exemplo n.º 8
0
 public static void BeginRespawning(GameNotifications gameNotifications)
 {
     gameNotifications.Publish(GameNotification.Respawning);
 }
Exemplo n.º 9
0
 public static void BeginDying(GameState gameState, GameNotifications gameNotifications)
 {
     gameState.HideGhosts();
     gameNotifications.Publish(GameNotification.Dying);
 }
Exemplo n.º 10
0
 public static void Tick(GameState gameState, DateTime now, GameNotifications gameNotifications)
 {
     gameNotifications.Publish(GameNotification.PreTick);
     gameState.RecordLastTick(now);
 }