Dr_Max_Experience

Task 10

Aug 13th, 2021 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Homework_1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string userInput = "";
  14.             string userName = "";
  15.             string password = "";
  16.             while (userInput != "Esc")
  17.             {
  18.                 Console.Clear();
  19.                 Console.Write("Список команд\nSetName – установить имя\nChangeConsoleColor - изменить цвет консоли\nSetPassword – установить пароль" +
  20.                     "\nWriteName – вывести имя\nEsc – выход из программы\n\nВведите команду: ");
  21.                 userInput = Console.ReadLine();
  22.  
  23.                 switch (userInput)
  24.                 {
  25.                     case "SetName":
  26.                         if (userName == "")
  27.                         {
  28.                             Console.Write("Введите имя пользователя: ");
  29.                             userName = Console.ReadLine();
  30.                             Console.Write($"Теперь пользователя зовут {userName}.");
  31.                             Console.ReadKey();
  32.                         }
  33.                         else if (password == "")
  34.                         {
  35.                             Console.Write("Сначала задайте пароль!");
  36.                             Console.ReadKey();
  37.                         }
  38.                         else
  39.                         {
  40.                             Console.Write("Введите пароль: ");
  41.                             userInput = Console.ReadLine();
  42.                             if (userInput == password)
  43.                             {
  44.                                 Console.Write("Введите новое имя пользователя: ");
  45.                                 userName = Console.ReadLine();
  46.                                 Console.Write($"Теперь пользователя зовут {userName}.");
  47.                                 Console.ReadKey();
  48.                             }
  49.                             else
  50.                             {
  51.                                 Console.Write("Неверный пароль!");
  52.                                 Console.ReadKey();
  53.                             }
  54.                         }
  55.                         break;
  56.  
  57.                     case "ChangeConsoleColor":
  58.                         Console.Write("Введите цвет (black, red, blue, magenta, green, gray): ");
  59.                         userInput = Console.ReadLine();
  60.                         switch (userInput)
  61.                         {
  62.                             case "black":
  63.                                 Console.BackgroundColor = ConsoleColor.Black;
  64.                                 break;
  65.                             case "red":
  66.                                 Console.BackgroundColor = ConsoleColor.DarkRed;
  67.                                 break;
  68.                             case "blue":
  69.                                 Console.BackgroundColor = ConsoleColor.DarkBlue;
  70.                                 break;
  71.                             case "magenta":
  72.                                 Console.BackgroundColor = ConsoleColor.DarkMagenta;
  73.                                 break;
  74.                             case "green":
  75.                                 Console.BackgroundColor = ConsoleColor.DarkGreen;
  76.                                 break;
  77.                             case "gray":
  78.                                 Console.BackgroundColor = ConsoleColor.DarkGray;
  79.                                 break;
  80.                         }
  81.                         break;
  82.  
  83.                     case "SetPassword":
  84.                         if(password == "")
  85.                         {
  86.                             Console.Write("Придумайте пароль: ");
  87.                             password = Console.ReadLine();
  88.                             Console.Write("Пароль установлен.");
  89.                             Console.ReadKey();
  90.                         }
  91.                         else
  92.                         {
  93.                             Console.Write("Введите существующий пароль: ");
  94.                             userInput = Console.ReadLine();
  95.                             if(userInput == password)
  96.                             {
  97.                                 Console.Write("Придумайте новый пароль: ");
  98.                                 userInput = Console.ReadLine();
  99.                                 Console.Write("Пароль установлен.");
  100.                                 Console.ReadKey();
  101.                             }
  102.                             else
  103.                             {
  104.                                 Console.Write("Неверный пароль!");
  105.                                 Console.ReadKey();
  106.                             }
  107.                         }
  108.                         break;
  109.  
  110.                     case "WriteName":
  111.                         if (userName == "")
  112.                         {
  113.                             Console.Write("Сначала задайте имя!");
  114.                             Console.ReadKey();
  115.                         }
  116.                         else if (password == "")
  117.                         {
  118.                             Console.Write("Сначала задайте пароль!");
  119.                             Console.ReadKey();
  120.                         }
  121.                         else
  122.                         {
  123.                             Console.Write("Ведите пароль: ");
  124.                             userInput = Console.ReadLine();
  125.                             if (userInput == password)
  126.                             {
  127.                                 Console.Write($"Имя пользователя: {userName}");
  128.                                 Console.ReadKey();
  129.                             }
  130.                             else
  131.                             {
  132.                                 Console.Write("Неверный пароль!");
  133.                                 Console.ReadKey();
  134.                             }
  135.                         }
  136.                         break;
  137.                     case "Esc":
  138.                         break;
  139.                     default:
  140.                         Console.Write("Такой команды нет!");
  141.                         Console.ReadKey();
  142.                         break;
  143.                 }
  144.             }
  145.         }
  146.     }
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment