Example #1
0
 internal MyStrategy(SfmlVisualizer p)
 {
     this.p = p;
 }
Example #2
0
        public void Start()
        {
            if (Visualizer != null)
            {
                throw new InvalidOperationException("Visualizer is already initialized.");
            }

            Visualizer = new SfmlVisualizer();
            Visualizer.SetStaticData(this.extendedRunnerModel.Game.LevelUpXpValues.Sum(), this.extendedRunnerModel.Game.LevelUpXpValues.Length);

            Visualizer.ToggleAudio += (sender, enableAudio) =>
            {
                if (enableAudio && BackgroundMusic == null)
                {
                    BackgroundMusic = Audios.PlayBackgroundMusic();
                }
                else if (!enableAudio && BackgroundMusic != null)
                {
                    BackgroundMusic.Stop();
                    BackgroundMusic.Dispose();
                    BackgroundMusic = null;
                }
            };

            Visualizer.ToggleTargetObserving += (sender, observe) =>
            {
                targetUnitId = null;
                targetUnit   = null;
            };

            string debugText = "";

            Visualizer.LeftMousePressed += (sender, position) =>
            {
                debugText = string.Format("{0};{1}", position.X, position.Y);
                Unit nearestUnit = extendedRunnerModel.AllWizards.Values
                                   .Cast <LivingUnit>()
                                   .Union(extendedRunnerModel.AllBuildings.Values)
                                   .Union(extendedRunnerModel.AllMinions.Values)
                                   .Select(
                    x =>
                {
                    var distanceTo = x.GetDistanceTo(position.X, position.Y);
                    return(new
                    {
                        Distance = distanceTo > x.Radius * TargetSelectionRadiusK ? (double?)null : distanceTo,
                        Unit = x
                    });
                })
                                   .Where(x => x.Distance.HasValue)
                                   .OrderBy(x => x.Distance.Value)
                                   .Select(x => x.Unit)
                                   .FirstOrDefault();
                if (nearestUnit != null)
                {
                    bool canObserve = false;
                    if (nearestUnit is Building)
                    {
                        if (nearestUnit.Faction == Faction.Academy)
                        {
                            if (((Building)nearestUnit).Type == BuildingType.FactionBase)
                            {
                                Audios.Union_Base_Selected();
                            }
                            else
                            {
                                Audios.Union_Tower_Selected();
                            }
                        }
                        else if (nearestUnit.Faction == Faction.Renegades)
                        {
                            if (((Building)nearestUnit).Type == BuildingType.FactionBase)
                            {
                                Audios.Enemy_Base_Selected();
                            }
                            else
                            {
                                Audios.Enemy_Tower_Selected();
                            }
                        }
                    }
                    else if (nearestUnit is Wizard)
                    {
                        if (nearestUnit.Faction == Faction.Academy)
                        {
                            Audios.Wizard_Selected_Union();
                            canObserve = true;
                        }
                        else if (nearestUnit.Faction == Faction.Renegades)
                        {
                            Audios.Wizard_Selected_Enemy();
                            canObserve = true;
                        }
                    }
                    else if (nearestUnit is Minion)
                    {
                        if (nearestUnit.Faction == Faction.Academy)
                        {
                            Audios.Minion_Selected_Union(((Minion)nearestUnit).Type == MinionType.FetishBlowdart);
                            canObserve = true;
                        }
                        else if (nearestUnit.Faction == Faction.Renegades)
                        {
                            Audios.Minion_Selected_Enemy(((Minion)nearestUnit).Type == MinionType.FetishBlowdart);
                            canObserve = true;
                        }
                    }
                    if (canObserve)
                    {
                        targetUnitId = nearestUnit.Id;
                        targetUnit   = null;
                        Visualizer.EnableTargetObservation();
                    }
                }
            };
        }