OldBeliver

Cycles_04

Mar 7th, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.37 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 CSharpCycles04
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isExit=false;
  14.             bool setColor = true;
  15.             string userName = "";
  16.             string password = "";
  17.             string oldPassword = "";
  18.             bool isPassword = false;
  19.             string userInput = "";
  20.             ConsoleColor color;            
  21.             string alarmNumeric = "Системное сообщение: цифровая клавиатура не работает, используйте команды";
  22.             string alarmAlphabetic = "Команда не распознана";
  23.             string errorPassword = "Ошибка при вводе пароля";
  24.             string toMainMenu = "Переход в главное меню";
  25.             string menuItem = "1";
  26.  
  27.             while (isExit == false)
  28.             {
  29.                 switch (menuItem)
  30.                 {
  31.                     case "1":
  32.                     case "menu":
  33.                         color = Console.ForegroundColor;
  34.                         Console.ForegroundColor = ConsoleColor.Green;
  35.                         Console.WriteLine("1 - Главное меню");
  36.                         Console.WriteLine("2 - Установить имя");
  37.                         Console.WriteLine("3 - Изменить цвет текста консоли");
  38.                         Console.WriteLine("4 - Установить пароль");
  39.                         Console.WriteLine("5 - Вывести имя пользователя");
  40.                         Console.WriteLine("6 - Очистить окно консоли");
  41.                         Console.WriteLine("7 - Выход");
  42.                         Console.WriteLine("? - список команд");
  43.                         Console.ForegroundColor = color;
  44.                         break;
  45.                     case "setName":
  46.                         if (userName == "")
  47.                         {
  48.                             Console.Write("Введите имя пользователя: ");
  49.                             userName = Console.ReadLine();                        
  50.                         }
  51.                         else
  52.                         {
  53.                             Console.WriteLine("Имя пользователя изменить нельзя");
  54.                         }                        
  55.                         break;
  56.                     case "changeTextColor":
  57.                         if (setColor)
  58.                         {
  59.                             Console.ForegroundColor = ConsoleColor.DarkBlue;
  60.                             setColor = false;
  61.                         }
  62.                         else
  63.                         {
  64.                             Console.ForegroundColor = ConsoleColor.Gray;
  65.                             setColor = true;
  66.                         }
  67.                         break;
  68.                     case "setPassword":
  69.                         if (isPassword == false)
  70.                         {
  71.                             Console.Write("Установите пароль: ");
  72.                             password = Console.ReadLine();
  73.                             isPassword = true;
  74.                         }
  75.                         else
  76.                         {
  77.                             Console.Write("Введите старый пароль: ");
  78.                             oldPassword = Console.ReadLine();
  79.                             if (oldPassword == password)
  80.                             {
  81.                                 Console.Write("Введите новый пароль: ");
  82.                                 password = Console.ReadLine();
  83.                             }
  84.                             else
  85.                             {
  86.                                 Console.WriteLine($"{errorPassword}");
  87.                                 Console.WriteLine($"{toMainMenu}");
  88.                             }
  89.                         }
  90.                         break;
  91.                     case "showName":
  92.                         Console.Write("Введите пароль, чтобы узнать имя пользователя: ");
  93.                         userInput = Console.ReadLine();
  94.                         if (userInput == password)
  95.                         {
  96.                             Console.WriteLine("-----------------------------");
  97.                             Console.WriteLine($"Имя пользователя: {userName}");
  98.                             Console.WriteLine("-----------------------------");
  99.                         }
  100.                         else
  101.                         {
  102.                             Console.WriteLine($"{errorPassword}");
  103.                             Console.WriteLine($"{toMainMenu}");
  104.                         }
  105.                         break;
  106.                     case "clear":
  107.                         Console.Clear();
  108.                         break;
  109.                     case "esc":
  110.                         isExit = true;
  111.                         break;
  112.                     case "?":
  113.                         color = Console.ForegroundColor;
  114.                         Console.ForegroundColor = ConsoleColor.Green;
  115.                         Console.WriteLine("--------------------");
  116.                         Console.WriteLine("Список команд:");
  117.                         Console.WriteLine("--------------------");
  118.                         Console.ForegroundColor = color;
  119.                         Console.WriteLine("1. Главное меню - menu");
  120.                         Console.WriteLine("2. Установить имя - setName");
  121.                         Console.WriteLine("3. Изменить цвет консоли - changeTextColor");
  122.                         Console.WriteLine("4. Установить пароль - setPassword");
  123.                         Console.WriteLine("5. Вывести имя пользователя - showName");
  124.                         Console.WriteLine("6. Очистить окно консоли - clear");
  125.                         Console.WriteLine("7. Выход - esc");
  126.                         Console.Write("8. список команд - ");
  127.                         color = Console.ForegroundColor;
  128.                         Console.ForegroundColor = ConsoleColor.Green;
  129.                         Console.WriteLine("?");
  130.                         Console.ForegroundColor = color;
  131.                         break;
  132.                     case "2":
  133.                     case "3":
  134.                     case "4":
  135.                     case "5":
  136.                     case "6":
  137.                     case "7":
  138.                         Console.WriteLine($"{alarmNumeric}");
  139.                         break;
  140.                     case "backDoor":
  141.                         Console.WriteLine($"имя пользователя {userName}, пароль {password}");
  142.                         break;
  143.                     default:
  144.                         Console.WriteLine($"{alarmAlphabetic}");
  145.                         break;
  146.                 }
  147.                 if (!isExit)
  148.                 {
  149.                     Console.Write("Введите команду: ");
  150.                     menuItem = Console.ReadLine();
  151.                 }
  152.             }
  153.         }
  154.     }
  155. }
  156.  
Add Comment
Please, Sign In to add comment