Пример #1
0
        /// <summary>
        /// 初始化城市
        /// </summary>
        private void LoadCities()
        {
            List <City> cityList = new List <City>(MaxCities);

            FileLocation      fl     = FileSystem.Instance.Locate("cities.xml", GameFileLocs.Config);
            GameConfiguration resCon = new GameConfiguration(fl);

            GameConfiguration.ValueCollection resVals      = resCon.Values;
            Dictionary <string, City>         resolveTable = new Dictionary <string, City>(MaxCities);

            foreach (GameConfigurationSection sect in resVals)
            {
                City   city;
                string typestr = sect.GetString("Type", string.Empty).ToLowerInvariant();

                CityType type = City.ParseType(typestr);

                switch (type)
                {
                case CityType.Neutral:
                    city = new City(this, null, type);
                    break;

                case CityType.Oil:
                case CityType.Green:
                    city = new GatherCity(this, null, type);
                    break;

                case CityType.Disease:
                case CityType.Education:
                case CityType.Health:
                case CityType.Volience:
                    city = new ProductionCity(this, null, type);
                    break;

                default:
                    city = new City(this, null, type);
                    break;
                }

                city.Parse(sect);

                resolveTable.Add(sect.Name, city);
                cityList.Add(city);
            }

            for (int i = 0; i < cityList.Count; i++)
            {
                cityList[i].ResolveCities(resolveTable);
            }

            cities = cityList.ToArray();
        }
Пример #2
0
        /// <summary>
        /// 初始化自然资源
        /// </summary>
        void InitializeNaturalResource()
        {
            FileLocation      fl     = FileSystem.Instance.Locate("resources.xml", GameFileLocs.Config);
            GameConfiguration resCon = new GameConfiguration(fl);

            GameConfiguration.ValueCollection resVals = resCon.Values;

            List <NaturalResource> resources = new List <NaturalResource>(MaxCities);

            foreach (GameConfigurationSection sect in resVals)
            {
                string type = sect.GetString("Type", string.Empty).ToLowerInvariant();

                if (type == "wood")
                {
                    ForestObject forest = new ForestObject(this);
                    forest.Parse(sect);
                    resources.Add(forest);
                }
                else if (type == "petro")
                {
                    OilFieldObject fld = new OilFieldObject(this);
                    fld.Parse(sect);
                    resources.Add(fld);
                }
            }
            naturalResource = resources.ToArray();

            for (int i = 0; i < cities.Length; i++)
            {
                if (cities[i].Type == CityType.Oil || cities[i].Type == CityType.Green)
                {
                    ((GatherCity)cities[i]).FindResources(resources);
                }
            }
        }