Esempio n. 1
0
        public void WelcomeAction()
        {
            CountryListView countryListHolder = new CountryListView(CountryDb);

            string input;
            int    countryNumSelection;
            int    countryIndex = 0;
            bool   runBehaviour = true;

            while (runBehaviour)
            {
                Console.WriteLine($"Hello, welcome to {ProgramName} app. Please select a country from the following list:\n");
                countryListHolder.Display();
                input = ReadAndReturnInput();

                try
                {
                    countryNumSelection = int.Parse(input);
                    if (countryNumSelection <= ReturnNumberInList(CountryDb))
                    {
                        foreach (Country country in CountryDb)
                        {
                            countryIndex++;
                            if (countryNumSelection == countryIndex)
                            {
                                CountryAction(country);
                                ChangeConsoleColor(country);
                                if (!CheckIfProgramShouldReRun(ProgramName))
                                {
                                    runBehaviour = false;
                                }
                            }
                        }
                        countryIndex = 0;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("The number you entered is greater than the amount of countries our database." +
                                          $"\nPlease enter a number less than {ReturnNumberInList(CountryDb)}\n");
                    }
                }
                catch (FormatException notANum)
                {
                    Console.Clear();
                    Console.WriteLine("Invalid input! Please enter a number.\n");
                }
                catch (OverflowException tooBig)
                {
                    Console.Clear();
                    Console.WriteLine($"The number you entered was out of range. Please enter a number from 1 to {ReturnNumberInList(CountryDb)}\n");
                }

                int counter = 0;
                foreach (Country country in countryListHolder.Countries)
                {
                    counter++;
                }
            }
        }
Esempio n. 2
0
        public void WelcomeAction()
        {
            List <Country> countrydb = new List <Country>()
            {
                new Country()
                {
                    Name = "United States of America", Colors = new List <string>()
                    {
                        "Red", "White", "Blue"
                    }, Continent = Continent.NorthAmerica
                },
                new Country()
                {
                    Name = "Greece", Colors = new List <string> {
                        "Blue", "White"
                    }, Continent = Continent.Europe
                },
                new Country()
                {
                    Name = "Australia", Colors = new List <string> {
                        "Green", "Gold"
                    }, Continent = Continent.Australia
                },
                new Country()
                {
                    Name = "Canada", Colors = new List <string> {
                        "Red", "White"
                    }, Continent = Continent.NorthAmerica
                },
                new Country()
                {
                    Name = "Japan", Colors = new List <string> {
                        "Red", "White"
                    }, Continent = Continent.Asia
                },
                new Country()
                {
                    Name = "Morocco", Colors = new List <string> {
                        "Red", "Green"
                    }, Continent = Continent.Africa
                },
            };


            CountryListView cv = new CountryListView(countrydb);

            Console.WriteLine("Hello, welcome to the country app. Please select a country from the following list:");
            cv.Display();

            int selection = int.Parse(Console.ReadLine());

            for (int i = 0; i < countrydb.Count; i++)
            {
                if ((selection - 1) == i)
                {
                    CountryAction(countrydb[i]);
                }
            }
        }
Esempio n. 3
0
        public void WelcomeAction()
        {
            CountryDataBase countryDB = new CountryDataBase();

            CountryListView countryListView = new CountryListView(countryDB.Countries);

            Console.WriteLine("\t\tHello, and welcome to the country app!\n" +
                              "\n" +
                              "Please select a country from the following list:\n" +
                              "");
            countryListView.Display();

            int selection = int.Parse(Console.ReadLine());

            CountryAction(countryDB.Countries[selection - 1]);
        }