Beispiel #1
0
        private void OnParentChanged(ParentChangedEngineEventArgs args)
        {
            if (TryTransition())
            {
                return;
            }

            CurrentStrategy?.OnParentChanged(args, this, CurrentState);
        }
Beispiel #2
0
        private void OnUpdate(EngineUpdateEventArgs args)
        {
            if (TryTransition())
            {
                return;
            }

            CurrentStrategy?.OnUpdate(args, this, CurrentState);
        }
Beispiel #3
0
        internal Ghost Move(Game game, IReadOnlyGameState gameState)
        {
            if (Edible && gameState.TickCounter % 2 == 1)
            {
                return(this);
            }

            if (GhostWalkingOutOfGhostHouse(game))
            {
                if (game.StartingCoins.Count - game.Coins.Count >= NumberOfCoinsRequiredToExitHouse)
                {
                    var outDirection = Direction.Up;
                    var target       = game.Doors.First().Above;
                    if (target.X < Location.X)
                    {
                        outDirection = Direction.Left;
                    }
                    else if (target.X > Location.X)
                    {
                        outDirection = Direction.Right;
                    }
                    var newGhostLocation = Location + outDirection;

                    return(WithNewLocationAndDirection(newGhostLocation, outDirection));
                }
                else
                {
                    return(this);
                }
            }

            var nextDirection = CurrentStrategy.GetNextDirection(this, game);

            if (nextDirection is Direction newDirection)
            {
                var newGhostLocation = Location + newDirection;
                if (game.Portals.TryGetValue(newGhostLocation, out var otherEndOfThePortal))
                {
                    newGhostLocation = otherEndOfThePortal + newDirection;
                }
                if (game.GhostHouse.Contains(newGhostLocation))
                {
                    return(WithNewLocationAndDirection(newGhostLocation, newDirection)
                           .WithNewStatusAndStrategy(GhostStatus.Alive, ChaseStrategy));
                }
                return(WithNewLocationAndDirection(newGhostLocation, newDirection));
            }
            else
            {
                return(this);
            }
        }
    public void GenerateResources(LocationLevelSettings currentSettings, ConfigurationData.PickableResourcesGenerationStrategyType strategyType)
    {
        StrategyOfGenerationResources CurrentStrategy;

        if (strategyType == ConfigurationData.PickableResourcesGenerationStrategyType.ExactlyInUnits)
        {
            CurrentStrategy = new ExactlyInUnitsStrategy();
        }
        else
        {
            CurrentStrategy = new FullRandomStrategy();
        }
        CurrentStrategy.StartGenerationResources(currentSettings, GoldPrefab, CrystallPrefab, GoldParentObject, CrystallParentObject);
    }
Beispiel #5
0
        public Ghost Move(Game game)
        {
            var newDirection = CurrentStrategy.GetNextDirection(this, game);

            var newLocation = newDirection switch
            {
                Direction.Up => Location.Above,
                Direction.Down => Location.Below,
                Direction.Left => Location.Left,
                Direction.Right => Location.Right,
                _ => Location
            };

            return(new Ghost(Name, Home, newLocation, newDirection ?? Direction, ScatterTarget, Strategy, CurrentStrategy, Edible));
        }
Beispiel #6
0
 public int Fight()
 {
     return(CurrentStrategy.Fight(this));
 }
Beispiel #7
0
 public void Act()
 {
     Health -= 1;
     CurrentStrategy?.Act(this);
 }