AlexStraga87

Команды

Feb 14th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.25 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string commandInput = "";
  14.             string userName = "User1";
  15.             string userPassword = "";
  16.  
  17.             Console.WriteLine("Добро пожаловать. Введите команду. Для списка введите List");
  18.  
  19.             while (commandInput != "Exit")
  20.             {
  21.                 Console.Write("Команда: ");
  22.                 commandInput = Console.ReadLine();
  23.  
  24.                 switch (commandInput)
  25.                 {
  26.                     case "List":
  27.                         Console.WriteLine("Список команд:");
  28.                         Console.WriteLine("List - вывести список команд");
  29.                         Console.WriteLine("SetPass - установить/изменить пароль");
  30.                         Console.WriteLine("SetName - Задать/изменить имя пользователя");
  31.                         Console.WriteLine("WriteName - вывести текущее имя пользователя");
  32.                         Console.WriteLine("Clear - очистить окно консоли");
  33.                         Console.WriteLine("Exit - Выход из программы");
  34.                         break;
  35.  
  36.                     case "SetPass":
  37.                         if (userPassword == "")
  38.                         {
  39.                             Console.Write("Установка пароля: ");
  40.                             string userPasswordInput1 = Console.ReadLine();
  41.                             Console.Write("Повторите пароль: ");
  42.                             string userPasswordInput2 = Console.ReadLine();
  43.                             if (userPasswordInput1 == userPasswordInput2)
  44.                             {
  45.                                 Console.WriteLine("Пароль установлен");
  46.                                 userPassword = userPasswordInput1;
  47.                             }
  48.                             else
  49.                             {
  50.                                 Console.WriteLine("Пароли не совпадают. Пароль не установлен!");
  51.                             }
  52.                         }
  53.                         else
  54.                         {
  55.                             Console.Write("Для смены пароля введите текущий: ");
  56.                             string userPasswordInput1 = Console.ReadLine();
  57.                             string userPasswordInput2;
  58.  
  59.                             if (userPassword == userPasswordInput1)
  60.                             {
  61.                                 Console.Write("Установка пароля: ");
  62.                                 userPasswordInput1 = Console.ReadLine();
  63.                                 Console.Write("Повторите пароль: ");
  64.                                 userPasswordInput2 = Console.ReadLine();
  65.                                 if (userPasswordInput1 == userPasswordInput2)
  66.                                 {
  67.                                     Console.WriteLine("Пароль установлен");
  68.                                     userPassword = userPasswordInput1;
  69.                                 }
  70.                                 else
  71.                                 {
  72.                                     Console.WriteLine("Пароли не совпадают. Пароль не установлен!");
  73.                                 }
  74.                             }
  75.                             else
  76.                             {
  77.                                 Console.WriteLine("Неверный пароль!");
  78.                             }
  79.                         }
  80.  
  81.                         break;
  82.  
  83.                     case "SetName":
  84.                         Console.Write("Для смены имени введите пароль: ");
  85.  
  86.                         string userPasswordInput = Console.ReadLine();
  87.                         if (userPassword == userPasswordInput)
  88.                         {
  89.                             Console.Write("Введите новое имя: ");
  90.                             userName = Console.ReadLine();
  91.                         }
  92.                         else
  93.                         {
  94.                             Console.WriteLine("Неверный пароль!");
  95.                         }                        
  96.                         break;
  97.  
  98.                     case "WriteName":
  99.                         Console.WriteLine(userName);
  100.                         break;
  101.  
  102.                     case "Clear":
  103.                         Console.Clear();
  104.                         break;
  105.  
  106.                     case "Exit":
  107.                         Console.WriteLine("Для закрытия окна нажмите любую клавишу");
  108.                         break;
  109.                     default:
  110.                         Console.WriteLine("Неизвестная команда");
  111.                         break;
  112.                 }
  113.  
  114.             }
  115.  
  116.             Console.ReadKey();
  117.  
  118.         }
  119.     }
  120. }
Add Comment
Please, Sign In to add comment