public void HandleBuildCommand(Control control, ResourcesManager resourcesManager)
 {
     switch (control.Name) {
         case "BuildAirfield":
             if (resourcesManager.Money >= Settings.AirfieldCost) {
                 IsAirfieldBuilt = true;
                 resourcesManager.Money -= Settings.AirfieldCost;
                 control.IsEnabled = false;
             }
             control.IsSelected = false;
             break;
         case "BuildControlTower":
             if (resourcesManager.Money >= Settings.ControlTowerCost) {
                 IsControlTowerBuilt = true;
                 resourcesManager.Money -= Settings.ControlTowerCost;
                 control.IsEnabled = false;
             }
             control.IsSelected = false;
             break;
     }
 }
Esempio n. 2
0
        private static void _HandleUnitControlSelection(InputState input, Control control, ContentManager content)
        {
            if (Selection.IsUnit) {
                var unit = Selection.SelectedSprite as Unit;
                if (control.Name == "Move"){
                    if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewLeftMouseClick()) {
                        unit.Destination = new Vector2(Mouse.X - unit.Bounds.Width/2,
                                                       Mouse.Y - unit.Bounds.Height/2);
                        control.IsSelected = false;
                    }
                }
                else if (control.Name == "BuildSolarPanel") {
                    if (!_isBuildingSolarPanel) {
                        unit = Selection.SelectedSprite as Truck;
                        unit.IsBuilding = true;
                        _isBuildingSolarPanel = true;
                        _solarPanelTexture = content.Load<Texture2D>(@"Textures\Buildings\SolarPlant");
                    }

                    if (_isBuildingSolarPanel &&
                        input.IsNewLeftMouseClick()) {
                            var solarPanel = new StaticBuilding(Mouse, @"Textures\Buildings\SolarPlant", 30);
                            solarPanel.LoadContent(content);
                            Sprites.Add(solarPanel);
                            ResourcesManager.Money -= Settings.SolarPanelCost;
                            ResourcesManager.MaxEnergy += Settings.SolarPanelEnergy;
                            control.IsSelected = false;
                            _isBuildingSolarPanel = false;
                    }
                    if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewRightMouseClick())
                    {
                        _isBuildingSolarPanel = false;
                        unit.IsBuilding = false;
                        control.IsSelected = false;
                    }
                }

                else if (control.Name == "BuildWindTurbine")
                {
                    unit = Selection.SelectedSprite as Truck;
                    unit.IsBuilding = true;
                    _isBuildingWindTurbine = true;
                    _windTurbineTexture = content.Load<Texture2D>(@"Textures\Buildings\WindTurbineSingleSprite");

                    if ((Vector2.Distance(Mouse, unit.Position) <= unit.Range) && input.IsNewLeftMouseClick())
                    {
                        var windTurbine = new AnimatedBuilding(Mouse, @"Textures\Buildings\WindTurbine", 30);
                        windTurbine.LoadContent(content);
                        Sprites.Add(windTurbine);
                        ResourcesManager.Money -= Settings.WindTurbineCost;
                        ResourcesManager.MaxEnergy += Settings.WindTurbineEnergy;
                        control.IsSelected = false;
                        _isBuildingWindTurbine = false;
                    }

                    if (input.CurrentMouseState.Y < (Camera.ViewSize.Y) && input.IsNewRightMouseClick())
                    {
                        unit.IsBuilding = false;
                        _isBuildingWindTurbine = false;
                        control.IsSelected = false;
                    }
                }
                else if (!control.Name.ToLower().Contains("load"))
                {
                    unit.HandleEnergyUpgrade(ResourcesManager.Money);
                    control.IsSelected = false;
                }
            }
        }
Esempio n. 3
0
        private static void _HandleDeployCommandAtHeadQuarter(Control control, ContentManager content)
        {
            Unit unit = null;
            if (control.Name == "DeployCar") {
                    unit = new Car(new Vector2(HeadQuarter.Position.X - HeadQuarter.Texture.Width/2,
                                               HeadQuarter.Position.Y + HeadQuarter.Texture.Height),
                                   0, new Vector2(105f, 79f), 1);
            }
            else if (control.Name == "DeployTruck") {
                    unit = new Truck(new Vector2(HeadQuarter.Position.X - HeadQuarter.Texture.Width,
                                                 HeadQuarter.Position.Y + HeadQuarter.Texture.Height),
                                     0, new Vector2(160f, 120f), 6);
            }
            else if (control.Name == "DeployUAV") {
                if (Sprites.FindAll(s => s is UAV).Count < 1 &&
                    HeadQuarter.IsAirfieldBuilt) {
                    unit = new UAV(new Vector2(HeadQuarter.Position.X - 30,
                                                      HeadQuarter.Position.Y + 70),
                                          new Vector2(HeadQuarter.Position.X - 30,
                                                      HeadQuarter.Position.Y + 70), 0, new Vector2(93f, 93f), 1);
                }
            }
            else if (control.Name == "DeployOsprey") {
                if (Sprites.FindAll(s => s is Osprey).Count < 1 &&
                    HeadQuarter.IsControlTowerBuilt) {
                    unit = new Osprey(new Vector2(HeadQuarter.Position.X,
                                                  HeadQuarter.Position.Y + HeadQuarter.Texture.Height),
                                      0, new Vector2(300f, 300f), 4);
                }
            }

            if (unit != null) {
                if (ResourcesManager.MaxEnergy - ResourcesManager.Energy >= unit.EnergyCosts[unit.EngineLevel] &&
                    ResourcesManager.Money >= unit.PurchasingCost) {
                    unit.LoadContent(content);
                    Sprites.Add(unit);
                    ResourcesManager.Money -= unit.PurchasingCost;
                    ResourcesManager.Energy += unit.EnergyCosts[unit.EngineLevel];
                }
            }
            control.IsSelected = false;
        }