W1thr

Функции-6

Jun 12th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.35 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 Homework4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string name = "";
  14.             string password = "";
  15.  
  16.             string userInput;
  17.             bool isActive = true;
  18.  
  19.             while (isActive == true)
  20.             {
  21.                 Console.WriteLine("--Команды--\n|Установить имя|\n|Изменить цвет консоли|\n|Установить пароль|\n|Вывести имя (после ввода пароля)|\n|Выход из программы|");
  22.                 userInput = Console.ReadLine();
  23.                 switch (userInput)
  24.                 {
  25.                     case "Установить имя":
  26.                         SetName(out name);
  27.                         break;
  28.                     case "Изменить цвет консоли":
  29.                         ChangeConsoleColor();
  30.                         break;
  31.                     case "Установить пароль":
  32.                         SetPassword(out password);
  33.                         break;
  34.                     case "Вывести имя":
  35.                         WriteName(password, name);
  36.                         break;
  37.                     case "Выход из программы":
  38.                         Esc();
  39.                         break;
  40.                     default:
  41.                         Console.WriteLine("Ошибка ввода...");
  42.                         break;
  43.  
  44.                 }
  45.  
  46.                 Console.ReadKey();
  47.                 Console.Clear();
  48.             }
  49.  
  50.         }
  51.  
  52.         static void SetName(out string name)
  53.         {
  54.             name = Console.ReadLine();
  55.             Console.WriteLine($"Имя изменено на {name}");
  56.         }
  57.  
  58.         static void ChangeConsoleColor()
  59.         {
  60.             Console.WriteLine("Выберите цвет(Green, Red или Break)");
  61.             string userColor = Console.ReadLine();
  62.             switch (userColor)
  63.             {
  64.                 case "Green":
  65.                     Console.ForegroundColor = ConsoleColor.Green;
  66.                     break;
  67.                 case "Red":
  68.                     Console.ForegroundColor = ConsoleColor.Red;
  69.                     break;
  70.                 case "Reset":
  71.                     Console.ForegroundColor = ConsoleColor.White;
  72.                     break;
  73.                 default:
  74.                     Console.WriteLine("Такого цвета нет!");
  75.                     break;
  76.             }
  77.         }
  78.  
  79.         static void SetPassword(out string password)
  80.         {
  81.             password = Console.ReadLine();
  82.             Console.WriteLine($"Пароль изменен на {password}");
  83.         }
  84.  
  85.         static void WriteName(string password, string name)
  86.         {
  87.             Console.WriteLine("Сначала введите пароль: ");
  88.  
  89.             if (password != "" && password != null)
  90.             {
  91.                 if (Console.ReadLine() == password)
  92.                     Console.WriteLine(name);
  93.                 else
  94.                     Console.WriteLine("Неверный пароль!");
  95.             }
  96.         }
  97.  
  98.         static void Esc()
  99.         {
  100.             Environment.Exit(0);
  101.         }
  102.     }
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment