Advertisement
Askor

Hw10

Jun 30th, 2020 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.48 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Test
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userInput;
  10.             string password;
  11.             string name;
  12.             string exit = "exit";
  13.             int randomNumber;
  14.  
  15.             do
  16.             {
  17.                 Console.WriteLine("------------------------------------------------");
  18.                 Console.WriteLine("Введите команду:\nChangeConsoleColor - Смена цвета консоли\nSetPassword - задть пароль\n" +
  19.                 "SetName - задать имя\nChangeTextColor - сменить цвет текста\nGetRandomNumber - получить случайное число\n" +
  20.                 "Esc - выход из программы");
  21.                 Console.Write("\nCommand: ");
  22.  
  23.                 userInput = Console.ReadLine();
  24.  
  25.                 switch (userInput)
  26.                 {
  27.                     case "ChangeConsoleColor":
  28.                         Console.WriteLine("Выберите цвет: 1 - red | 2 - Green | 3 - Yellow | 4 - Blue");
  29.                         userInput = Console.ReadLine();
  30.  
  31.                         switch (userInput)
  32.                         {
  33.                             case "1":
  34.                                 Console.BackgroundColor = ConsoleColor.Red;
  35.                                 Console.Clear();
  36.                                 break;
  37.                             case "2":
  38.                                 Console.BackgroundColor = ConsoleColor.Green;
  39.                                 Console.Clear();
  40.                                 break;
  41.                             case "3":
  42.                                 Console.BackgroundColor = ConsoleColor.Yellow;
  43.                                 Console.Clear();
  44.                                 break;
  45.                             case "4":
  46.                                 Console.BackgroundColor = ConsoleColor.Blue;
  47.                                 Console.Clear();
  48.                                 break;
  49.                         }
  50.                         break;
  51.                     case "SetPassword":
  52.                         Console.WriteLine("Задайте пароль: ");
  53.                         password = Console.ReadLine();
  54.  
  55.                         Console.WriteLine($"Вы установили пароль: {password}");
  56.  
  57.                         break;
  58.                     case "SetName":
  59.                         Console.WriteLine("Задайте имя: ");
  60.                         name = Console.ReadLine();
  61.  
  62.                         Console.WriteLine($"Вы задали имя: {name}");
  63.  
  64.                         break;
  65.  
  66.                     case "ChangeTextColor":
  67.                         Console.WriteLine("Выберите цвет: 1 - red | 2 - Green | 3 - Yellow | 4 - Blue");
  68.                         userInput = Console.ReadLine();
  69.  
  70.                         switch (userInput)
  71.                         {
  72.                             case "1":
  73.                                 Console.ForegroundColor = ConsoleColor.Red;
  74.                                 break;
  75.                             case "2":
  76.                                 Console.ForegroundColor = ConsoleColor.Green;
  77.                                 break;
  78.                             case "3":
  79.                                 Console.ForegroundColor = ConsoleColor.Yellow;
  80.                                 break;
  81.                             case "4":
  82.                                 Console.ForegroundColor = ConsoleColor.Blue;
  83.                                 break;
  84.                         }
  85.                         break;
  86.                     case "GetRandomNumber":
  87.                         Random rand = new Random();
  88.                         randomNumber = rand.Next(0, 101);
  89.  
  90.                         Console.WriteLine($"Случайное число от 0 до 100: {randomNumber}");
  91.  
  92.                         break;
  93.                     case "Esc":
  94.                         userInput = exit;
  95.                         break;
  96.                     default:
  97.                         if (userInput == exit)
  98.                         {
  99.                             break;
  100.                         }
  101.                         else
  102.                         {
  103.                             Console.WriteLine("Команда введена неверно.");
  104.                         }
  105.                         break;
  106.                 }
  107.             }
  108.             while (userInput != exit);
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement