Пример #1
0
        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));
            }
        }
Пример #2
0
 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 !));
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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));
            }
        }
        public async Task Execute(BehaviorContext <TInstance, MultiRequestFinishedSignal> context, Behavior <TInstance, MultiRequestFinishedSignal> next)
        {
            var evt = MultiRequestFinishedEvent <TInstance, TState, TRequest, TResponse> .Init(context, request);

            // settings indicate we should clear the state
            if (request.Settings.ClearOnFinish)
            {
                await request.Accessor.Clear(context);
            }

            await context.Raise(request.Finished, evt);

            await next.Execute(context);
        }
Пример #6
0
        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));
            }
        }
Пример #7
0
 public Task Raise(Event @event)
 {
     return(_context.Raise(@event));
 }
 Task RaiseCompositeEvent(BehaviorContext <TInstance> context)
 {
     return(context.Raise(_event));
 }
Пример #9
0
 public Task Raise(Event @event, CancellationToken cancellationToken = new CancellationToken())
 {
     return(_context.Raise(@event, cancellationToken));
 }