Ejemplo n.º 1
0
        // Main logic hub of the program, stuff branches out from here
        private bool EventLoop()
        {
            ConsoleMenuPainter.TextColor();
            bool finished = false;

            do
            {
                string[] menuItems = new string[] {
                    "1) Generate male names",
                    "2) Generate female names",
                    "3) Generate male and female names",
                    "4) Quit"
                };
                Console.Clear();
                Output.Intro();
                int userChoice = Menu.Selection(menuItems, 0, 12); // the two digits are to place the menu on the x and y axis

                if (userChoice == 3)
                {
                    Console.Clear();
                    Console.WriteLine("Quit");
                    finished = true;
                }
                else
                {
                    GenerateNames(userChoice);
                }
            } while (!finished);

            return(finished);
        }
Ejemplo n.º 2
0
 private void PrintNames()
 {
     foreach (var name in outputListOfNames)
     {
         ConsoleMenuPainter.TextColor();
         Console.WriteLine(name);
     }
 }
Ejemplo n.º 3
0
        //Intro text tells the user what this program does
        internal static void Intro()
        {
            ConsoleMenuPainter.TextColor();

            Console.WriteLine("Welcome, this is a simple Random Name Generator.\n\nIt gets the last names from the 2010 census.");
            Console.WriteLine("We are only using the last names that show up at least once in \n" +
                              "every 100,000 people you would likely meet in the United States.\n");
            Console.WriteLine("For the first and middle names I am using data from the Social Security Administration for the \n" +
                              "birth year of 2018 (the latest available at the time the program was written.\n\n" +
                              "What would you like to do? (Make your selection with the \n" +
                              "arrow or number key and then hit enter)");
        }
Ejemplo n.º 4
0
        // After the names have been generated, what does the user want to do with them?
        private void NowWhat()
        {
            ConsoleMenuPainter.TextColor();
            bool finished = false;

            do
            {
                Console.Clear();
                Console.WriteLine($"OK, I've generated all {outputListOfNames.Count} names.");
                Console.WriteLine("What would you like to do?\n");
                int userChoice = Elicit.WhatNowMenu(0, 5); // the two digits are to place the menu on the x and y axis

                switch (userChoice)
                {
                case 0:
                    Console.Clear();
                    Console.WriteLine("Print the names to the screen\n");
                    PrintNames();
                    Console.WriteLine("\n\nHit enter to continue");
                    Console.ReadLine();
                    finished = true;
                    break;

                case 1:
                    Console.Clear();
                    Console.WriteLine("Print the names to a file\n");
                    FileStuff.WriteToFile(outputListOfNames, "ListOfNames.txt");
                    finished = true;
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Both\n");
                    PrintNames();
                    FileStuff.WriteToFile(outputListOfNames, "ListOfNames.txt");
                    finished = true;
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Quit");
                    Console.ResetColor();
                    finished = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Default case");
                    finished = true;
                    break;
                }
            } while (!finished);
        }
        // Receives a string array and x and y coordinates to create the interactive menu at the x and y coordinates
        public static int Selection(string[] menuItems, int x, int y)
        {
            var menu = new Menu(menuItems);

            var countOfMenuItems = menuItems.Count();

            var menuPainter = new ConsoleMenuPainter(menu);

            bool done = false;

            do
            {
                menuPainter.Paint(x, y);

                var keyInfo = Console.ReadKey(true);

                menu.SelectedIndex = AlternateInputSelection(ref done, keyInfo, menu.SelectedIndex, countOfMenuItems);
                if (done)
                {
                    return(menu.SelectedIndex);
                }

                switch (keyInfo.Key)
                {
                case ConsoleKey.UpArrow: menu.MoveUp(); break;

                case ConsoleKey.DownArrow: menu.MoveDown(); break;

                case ConsoleKey.Enter:
                    done = true;
                    Console.ResetColor();
                    return(menu.SelectedIndex);

                default:
                    break;
                }
            }while (!done);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Selected option: " + (menu.SelectedOption ?? "(nothing)"));
            Console.ReadKey();
            return(9);
        }
Ejemplo n.º 6
0
        private void GenerateNames(int userChoice)
        {
            Console.Clear();
            ConsoleMenuPainter.TextColor();
            int  numberOfNames;
            bool middleNames;

            switch (userChoice)
            {
            case 0:
                Console.Clear();
                Console.WriteLine("Generate Male Names\n");
                (numberOfNames, middleNames) = GetNumberAndMiddleNameInput();
                outputListOfNames            = Rand.ListOfNames(numberOfNames, firstNamesMale, lastNames, outputListOfNames, middleNames);
                NowWhat();
                break;

            case 1:
                Console.Clear();
                Console.WriteLine("Generate Female Names\n");
                (numberOfNames, middleNames) = GetNumberAndMiddleNameInput();
                outputListOfNames            = Rand.ListOfNames(numberOfNames, firstNamesFemale, lastNames, outputListOfNames, middleNames);
                NowWhat();
                break;

            case 2:
                Console.Clear();
                Console.WriteLine("Generate Male and Female Names\n");
                (numberOfNames, middleNames) = GetNumberAndMiddleNameInput();
                outputListOfNames            = Rand.MaleAndFemaleNames(numberOfNames, firstNamesMale, firstNamesFemale, lastNames, outputListOfNames, middleNames);
                NowWhat();
                break;

            default:
                Console.Clear();
                Console.WriteLine("Default case");
                break;
            }
        }