Пример #1
0
        public void Menu()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.WriteLine(" \t \t \t ------МЕНЮ------- \t \t \t \n");
            Console.WriteLine("\t Выберите действие: \n 1 - Кормить \n 2 - Играть \n 3 - Спать \n 4 - Работать \n 5 - Выбрать характер \n 6 - Выход");

            Console.ForegroundColor = ConsoleColor.White;

        link: try
            {
                Console.WriteLine("Введите номер выбора");
                int input = Convert.ToInt32(Console.ReadLine());

                switch (input)
                {
                    case 1:                         
                        Human h1 = new Human();
                        h1.Feed();
                        break;
                    case 2:
                        Human h2 = new Human();
                        h2.Play();
                        break;
                    case 3:
                        Human h3 = new Human();
                        h3.Sleep();
                        break;
                    case 4:
                        Work h4 = new Work(HumanWorking);           // вызов делегата
                        string result = h4("");
                        break;
                    case 5:
                        Human h5 = new Human();
                        h5.Personality();
                        break;
                    case 6:
                        return;
                        }

                if (input < 1 || input > 7)
                {
                    Console.WriteLine("Проверьте введенное число!");
                    goto link;
                }

            }
            catch (FormatException)
            {
                Console.WriteLine("Число должно быть от 1 до 7");
                goto link;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.Yellow;
            Console.WriteLine(" \t \t \t Добро пожаловать!");
            //меню
            Console.ForegroundColor = ConsoleColor.Green;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.WriteLine(" \t \t \t ------МЕНЮ------- \t \t \t \n");

            Console.WriteLine("\t Выберите персонажа: \n 1 - Собака \n 2 - Кошка \n 3 - Человек \n 4 - Выход");
            Console.ForegroundColor = ConsoleColor.White;

            string [] species = new string [3];
            species[0] = "Собака";
            species[1] = "Кот";
            species[2] = "Человек";

            DateTime curDate = DateTime.Now;
            Console.WriteLine("Введите номер выбора \n");
            int input = Convert.ToInt32(Console.ReadLine());

            CreatureName nm = new CreatureName();                       // реализация свойства
            Console.WriteLine("Выберите имя для персонажа \n");             
            string n = Console.ReadLine();
            nm.Name = n;
            
            

            if (input == 1)
            {
                Console.WriteLine("Поздравляем! Вы завели питомца: " + (species[0]) + " " + "по имени " + " " + nm.Name + ". \n" + "Дата и время создания: " + curDate);
            }
            else if (input == 2)
            {
                Console.WriteLine("Поздравляем! Вы завели питомца: " + (species[1]) + " " + "по имени " + " " + nm.Name + ". \n" + "Дата и время создания: " + curDate);
            }
            else
            {
                Console.WriteLine("Поздравляем! Вы завели питомца: " + (species[2]) + " " + "по имени " + " " + nm.Name + ". \n" + "Дата и время создания: " + curDate + " \n ");
            }


        link: try
            {
            switch (input)
                 {
                    case 1:
                         Dog dg = new Dog();
                         dg.Menu();
                         break;
                    case 2:
                         Cat ct = new Cat();
                         ct.Menu();
                         break;
                    case 3:
                         Human hm = new Human();
                         hm.Menu();
                         break;
                    case 4: 
                         goto link;
                 }

             }

            catch (FormatException)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Читай внимательно! Надо вводить Ч-И-С-Л-О!");
                Console.ForegroundColor = ConsoleColor.White;
                goto link;
            }
            catch (input > 3)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Надо вводить число от 1 до 3");
                goto link;
            }

        Console.ReadLine();
          
        }
Пример #3
0
        public void Personality()
        {
            Human h1 = new Human();
            Console.WriteLine("Выберите характер: \n");
      
            string[] features = new string[6];
            features[0] = "Вредный";
            features[1] = "Добрый";
            features[2] = "Наглый";
            features[3] = "Заносчивый";
            features[4] = "Вспыльчивый";
            features[5] = "Отзывчивый \n";
            foreach (string i in features)
            {
                Console.WriteLine(i);
            }

            string s = Console.ReadLine();
            h1.Character = s;

            Console.WriteLine("Выбран характер:" + " " + h1.Character + "\n");

            Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
            Console.ReadLine();
            Menu();
        }
Пример #4
0
       static string HumanWorking(string empty)   // конструктор? реализация делегата
        {

            Console.WriteLine("Вы хотите отправить человека на работу? \t  1 - Да \n 0 - Нет");

            int input;

            input = Convert.ToInt32(Console.ReadLine());

            if (input == 1)
            {
                Console.WriteLine("Человек работает. Чтобы вернуться в основное меню, нажмите Enter \n");
                Console.ReadLine();
                Human hm = new Human();
                hm.Menu();
                return empty = "";
            }
            else
            {
                Human hm = new Human();
                hm.Menu();
                return empty = "";
            }
        }