Beispiel #1
0
 public static void BuildHandbook(Earth earth)
 {
     BuildEarth(earth);
     AddCountries(earth);
     AddRegions(earth);
     AddCities(earth);
 }
Beispiel #2
0
        private static int GetContinentIndex(Earth earth, TextReader reader)
        {
            string searchedValue = reader.ReadLine();
            int    j             = 0;

            while (j < earth.Length && earth[j].Name != searchedValue)
            {
                j++;
            }
            return(j);
        }
Beispiel #3
0
        private static void BuildEarth(Earth earth)
        {
            TextReader cont = new StreamReader(@"data/mainlands.txt");
            int        i;

            for (i = 0; i < 6; i++)
            {
                earth.AddChild(AddContinent(cont));
            }
            cont.Close();
        }
Beispiel #4
0
        private static void AddCountries(Earth earth)
        {
            TextReader countryList    = new StreamReader(@"data/countries.txt");
            int        numOfCountries = Convert.ToInt32(countryList.ReadLine());
            int        i;
            int        continentIndex;

            for (i = 0; i < numOfCountries; i++)
            {
                continentIndex = GetContinentIndex(earth, countryList);
                earth[continentIndex].AddChild(AddCountry(countryList));
            }
            countryList.Close();
        }
Beispiel #5
0
        private static void AddRegions(Earth earth)
        {
            TextReader      regionList = new StreamReader(@"data/regions.txt");
            int             i;
            int             continentIndex;
            int             numOfRegions = Convert.ToInt32(regionList.ReadLine());
            string          countryName;
            TerritoryObject searchedCountry;

            for (i = 0; i < numOfRegions; i++)
            {
                continentIndex  = GetContinentIndex(earth, regionList);
                countryName     = regionList.ReadLine();
                searchedCountry = earth[continentIndex].GetChildByName(countryName);
                if (searchedCountry != null)
                {
                    searchedCountry.AddChild(AddRegion(regionList));
                }
            }
        }
Beispiel #6
0
        private static void AddCities(Earth earth)
        {
            TextReader      cityList = new StreamReader(@"data/cities.txt");
            int             i;
            int             continentIndex;
            int             numOfCities = Convert.ToInt32(cityList.ReadLine());
            string          countryName;
            string          regionName;
            TerritoryObject searchedCountry;
            TerritoryObject searchedRegion;

            for (i = 0; i < numOfCities; i++)
            {
                continentIndex  = GetContinentIndex(earth, cityList);
                countryName     = cityList.ReadLine();
                regionName      = cityList.ReadLine();
                searchedCountry = earth[continentIndex].GetChildByName(countryName);
                searchedRegion  = searchedCountry.GetChildByName(regionName);
                searchedRegion.AddChild(AddCity(cityList));
            }
        }
Beispiel #7
0
        public static List <TerritoryObject> GetCountries(int quantity, Earth earth)
        {
            List <TerritoryObject> result = new List <TerritoryObject>();

            bool[,] selected = new bool[5, 20];
            int    i;
            int    index1, index2;
            Random random = new Random();

            for (i = 0; i < quantity; i++)
            {
                do
                {
                    index1 = random.Next(0, earth.Length - 1);
                    index2 = random.Next(0, earth[index1].Length);
                }while (selected[index1, index2]);
                selected[index1, index2] = true;
                result.Add(earth[index1][index2]);
            }
            return(result);
        }