Пример #1
0
 public void UpgradePopulationConstruction(Slot slot, Construction populationConstruction)
 {
     Reservation reservation = new Reservation(GameManager.CurrentYear, 500, populationConstruction);
     reservation.IsPopulationUpgraded = true;
     slot.MakeReservation(reservation);
 }
Пример #2
0
 public void ConfirmBuild(Slot slot)
 {
     int price = GameManager.BuildingProperties.BuildingBaseProperties(panel.SelectedBuilding, GameManager.CurrentYear, 0, GameManager.CurrentYear).Price;
     if (GameManager.GetMoney(GameManager.CurrentYear) >= price)
     {
         GameManager.SpendMoney(GameManager.CurrentYear, price);
         SetMoney(GameManager.GetMoney(GameManager.CurrentYear));
         Map.CreateBuilding(slot, panel.SelectedBuilding);
     }
     else
     {
         //Debug.AddToLog("Not enough cashcaval");
     }
 }
Пример #3
0
 public void UndoBuild(int year, Slot slot)
 {
     BuildingsBaseProperties properties = new BuildingsBaseProperties();
     int price = properties.BuildingBaseProperties(slot.GetReservation(year).ConstructionName,
         slot.GetReservation(year).StartingYear, year, year).Price;
     GUI.SetMoney(GameManager.GetMoney(year) + price);
     changesMade = true;
 }
Пример #4
0
        /// <summary>
        /// Refresh the building associated with a slot.
        /// </summary>
        /// <param name="slot"></param>
        public void RefreshBuilding(Slot slot)
        {
            //if the slot has a building already attached to it
            if (slot.CurrentConstruction != null)
            {
                //if the slot has a reservation in the current year
                if (slot.GetReservation(GameManager.CurrentYear) != null)
                {
                    //if the current building doesn't match the current reservation
                    if ((slot.GetReservation(GameManager.CurrentYear).StartingYear != slot.CurrentConstruction.ConstructionYear) ||
                        (slot.GetReservation(GameManager.CurrentYear).EndingYear != slot.CurrentConstruction.DestructionYear))
                    {
                        RemoveChild(slot.CurrentConstruction);
                        slot.CurrentConstruction = null;

                        SetNewBuilding(slot);
                    }
                    //if the building matches the current reservation
                    else
                    {
                        slot.CurrentConstruction.ChangeGraphics();
                    }

                }
                //if the slot has no reservation
                else
                {
                    RemoveChild(slot.CurrentConstruction);
                    slot.CurrentConstruction = null;
                }
            }
            //if the slot has no construction attached
            else
            {
                //if the slot has a reservation
                if (slot.GetReservation(GameManager.CurrentYear) != null)
                {
                    SetNewBuilding(slot);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Attach a new building to a slot.
        /// </summary>
        /// <param name="slot"></param>
        private void SetNewBuilding(Slot slot)
        {
            BuildingsBaseProperties properties = new BuildingsBaseProperties();
            BaseConstruction building;
            if (slot.ConstructionType != ConstructionType.Population)
            {
                building = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, false, false);
            }
            else
            {
                building = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, true, slot.GetReservation(GameManager.CurrentYear).IsPopulationUpgraded);
            }

            building.ConstructionName = slot.GetReservation(GameManager.CurrentYear).ConstructionName;
            building.ConstructionYear = slot.GetReservation(GameManager.CurrentYear).StartingYear;
            building.ConstructionLifetime = slot.GetReservation(GameManager.CurrentYear).Duration;
            building.ConstructionType = slot.ConstructionType;
            if (slot.GetReservation(GameManager.CurrentYear).IsDestroyed)
            {
                building.DegradationPeriod = 0;
            }
            else
            {
                building.DegradationPeriod = 1; //properties.BuildingBaseProperties(building.ConstructionName, building.ConstructionYear, building.UpgradeYear, GameManager.CurrentYear).DestructionPeriod;
            }
            building.ConstructingPeriod = properties.BuildingBaseProperties(building.ConstructionName, building.ConstructionYear, building.UpgradeYear, GameManager.CurrentYear).ConstructingPeriod;
            building.StackOrder = stackOrder_slots + 1;
            AddChild(building);
            building.ChangeGraphics();
            slot.CurrentConstruction = building;
            building.Slot = slot;

            building.OnSelected += new EventHandler(Building_OnSelected);
            RemoveConstructionPanel();
        }
Пример #6
0
 public void Upgrade(Slot slot, int year)
 {
     BuildingsBaseProperties properties = new BuildingsBaseProperties();
     int price = properties.BuildingBaseProperties(slot.GetReservation(year).ConstructionName,
         slot.GetReservation(year).StartingYear, year, year).Price;
     GameManager.SpendMoney(year, price / 10);
     GUI.SetMoney(GameManager.GetMoney(year));
     changesMade = true;
 }
Пример #7
0
        public void CreateBuilding(Slot slot, Construction building, int year)
        {
            BuildingsBaseProperties properties = new BuildingsBaseProperties();

            BaseConstruction newBuilding;
            if (slot.ConstructionType != ConstructionType.Population)
                newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, false, false);
            else
                newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, true, false);

            newBuilding.ConstructionName = building;
            newBuilding.ConstructionYear = year;
            newBuilding.ConstructionType = slot.ConstructionType;
            newBuilding.ConstructionLifetime = properties.BuildingBaseProperties(building, year, 0, year).Lifetime;
            newBuilding.ConstructingPeriod = properties.BuildingBaseProperties(building, year, 0, year).ConstructingPeriod;
            newBuilding.DegradationPeriod = properties.BuildingBaseProperties(building, year, 0, year).DestructionPeriod;
            newBuilding.StackOrder = stackOrder_slots + 1;
            newBuilding.ChangeGraphics();
            newBuilding.Slot = slot;

            AddChild(newBuilding);

            slot.CurrentConstruction = newBuilding;
            slot.MakeReservation(year, newBuilding.ConstructionLifetime, building);

            changesMade = true;

            GUI.ClearSelectedBuildingIcon();

            newBuilding.OnSelected += new EventHandler(Building_OnSelected);
            RemoveConstructionPanel();
        }
Пример #8
0
 public void SetConstructionReservation(Slot slot, Reservation reservation)
 {
 }
Пример #9
0
        /// <summary>
        /// Create a new building.
        /// </summary>
        /// <param name="slot">The slot on which to create the building.</param>
        /// <param name="building">The building type.</param>

        public void CreateBuilding(Slot slot, Construction building)
        {
            CreateBuilding(slot, building, GameManager.CurrentYear);
            RemoveConstructionPanel();
        }
Пример #10
0
        public GameMap(Game game, string Zone)
            : base(game)
        {
            changesMade = false;

            mapFile = zonesFolder + "\\" + Zone + "\\" + mapFile;

            //Loading the Map
            xmlLoaderMap = XElement.Load(mapFile);
            IEnumerable<XElement> mapData = from element in xmlLoaderMap.Elements() select element;
            int elementCount = 0;

            int w = 0;
            int h = 0;

            slotList = new List<Slot>();

            foreach (XElement data in mapData)
            {
                numberOfItemsToRead += data.Elements().Count();
            }

            List<Slot> historySlotList = ProfilesManager.LoadZoneHistory();
            numberOfItemsToRead += historySlotList.Count;

            foreach (XElement data in mapData) //3 categories: Map Dimensions, Map Elements, Slots
            {
                switch (elementCount)
                {
                    case 0: //reads the map dimensions and loades the ground

                        w = Convert.ToInt32(data.Element("Width").Value);
                        h = Convert.ToInt32(data.Element("Height").Value);

                        for (int i = 0; i < w; i++)
                        {
                            for (int j = 0; j < h; j++)
                            {
                                Sprite ground = new Sprite(game, GraphicsCollection.GetPack("ground"));
                                ground.StackOrder = stackOrder_map;
                                ground.XRelative = ground.Width * i;
                                ground.YRelative = ground.Height * j;
                                ground.FrameNumber = 0;
                                AddChild(ground);

                                width = w * ground.Width;
                                height = h * ground.Height;
                            }
                        }
                        numberOfItemsRead++;
                        DisplayManager.ChangePreloaderPercent(PercentCreated);
                        break;
                    case 1: //reads the map elements
                        IEnumerable<XElement> mapElements = from element in data.Elements() select element;

                        foreach (XElement mapElement in mapElements)
                        {
                            string TexturePack = Convert.ToString(mapElement.Element("TexturePack").Value);
                            int frameNumber = Convert.ToInt32(mapElement.Element("FrameNumber").Value);
                            int X = Convert.ToInt32(mapElement.Element("X").Value);
                            int Y = Convert.ToInt32(mapElement.Element("Y").Value);

                            Sprite mapSpriteElement = new Sprite(game, GraphicsCollection.GetPack(TexturePack).Frames[frameNumber]);
                            mapSpriteElement.StackOrder = stackOrder_map;
                            mapSpriteElement.XRelative = X;
                            mapSpriteElement.YRelative = Y;
                            mapSpriteElement.FrameNumber = 0;
                            AddChild(mapSpriteElement);

                            numberOfItemsRead++;
                            DisplayManager.ChangePreloaderPercent(PercentCreated);
                        }
                        break;
                    case 2: //reads the slots
                        IEnumerable<XElement> slotsData = from element in data.Elements() select element;

                        foreach (XElement slotElement in slotsData)
                        {
                            ConstructionType slot_constructionType = (ConstructionType)Enum.Parse(typeof(ConstructionType), Convert.ToString(slotElement.Element("ConstructionType").Value));

                            int X = Convert.ToInt32(slotElement.Element("X").Value);
                            int Y = Convert.ToInt32(slotElement.Element("Y").Value);

                            Slot slot;
                            slot = new Slot(game, slot_constructionType);
                            slot.StackOrder = stackOrder_slots;
                            slot.XSlotCenter = X;
                            slot.YSlotCenter = Y;
                            slot.Visible = false;
                            slot.OnSelected += new EventHandler(slot_OnSelected);
                            AddChild(slot);
                            slotList.Add(slot);

                            numberOfItemsRead++;
                            DisplayManager.ChangePreloaderPercent(PercentCreated);
                        }
                        break;
                        //case 3, se det slot-ul dupa x si y si se face instanta slot
                        // se face instanta reservation
                    //se trimit SetConstructionReservation(slot+reservation)                    
                }
                elementCount++;
            }

            //reading zone history
            for (int i = 0; i < slotList.Count; i++)
            {
                for (int j = 0; j < historySlotList.Count; j++)
                {
                    if (slotList[i].ConstructionType == historySlotList[j].ConstructionType &&
                        slotList[i].XSlotCenter == historySlotList[j].XSlotCenter &&
                        slotList[i].YSlotCenter == historySlotList[j].YSlotCenter)
                    {
                        slotList[i].ReservationList = historySlotList[j].ReservationList;
                        numberOfItemsRead++;
                        DisplayManager.ChangePreloaderPercent(PercentCreated);
                        break;
                    }
                }
            }

            Game.Services.AddService(typeof(GameMap), this);

            //test only, the population will be loaded from the saved game
            GameManager.LoadHistory();
            changesMade = true;
            GameManager.UpdateYear(2010);

            HideSlots();

            DisplayManager.GameMap_HidePreloader();
        }
Пример #11
0
        public List<Slot> LoadZoneHistory(String profilePath)
        {
            List<Slot> slotList = new List<Slot>();

            xmlLoader = XElement.Load(profilePath + "\\" + ZonesHistoryFile);
            IEnumerable<XElement> slotListData = from element in xmlLoader.Elements() select element;

            int xSlotCenter = 0;
            int ySlotCenter = 0;
            string constructionType = "";
            Slot currentSlot = null;
            Reservation currentReservation = null;

            foreach (XElement slot in slotListData)
            {
                xSlotCenter = Convert.ToInt32(slot.Element("X").Value);
                ySlotCenter = Convert.ToInt32(slot.Element("Y").Value);
                constructionType = slot.Element("constructionType").Value.ToString();
                currentSlot = new Slot(this.Game, (ConstructionType)Enum.Parse(typeof(ConstructionType), constructionType));
                currentSlot.XSlotCenter = xSlotCenter;
                currentSlot.YSlotCenter = ySlotCenter;
                IEnumerable<XElement> slotReservations = from element in slot.Elements("reservation") select element;

                foreach (XElement reservation in slotReservations)
                {
                    string constructionName = reservation.Element("constructionName").Value.ToString();
                    Construction construction = (Construction)Enum.Parse(typeof(Construction), constructionName);
                    int startingYear = Convert.ToInt32(reservation.Element("startingYear").Value);
                    int duration = Convert.ToInt32(reservation.Element("duration").Value);
                    int upgradeYear = Convert.ToInt32(reservation.Element("upgradeYear").Value);
                    bool isUpgraded = Convert.ToBoolean(reservation.Element("isUpgraded").Value);
                    bool isPopulationUpgraded = Convert.ToBoolean(reservation.Element("isPopulationUpgraded").Value);
                    bool isDestroyed = Convert.ToBoolean(reservation.Element("isDestroyed").Value);

                    currentReservation = new Reservation(startingYear, duration, construction);
                    currentReservation.UpgradeYear = upgradeYear;
                    currentReservation.IsUpgraded = isUpgraded;
                    currentReservation.IsPopulationUpgraded = isPopulationUpgraded;
                    currentReservation.IsDestroyed = isDestroyed;

                    currentSlot.MakeReservation(currentReservation);
                    slotList.Add(currentSlot);
                }
            }
                
            return slotList;
        }