Advertisement
holllowknight

ДЗ: Консольное меню

Mar 8th, 2020 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleMenu
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const string CommandReduceWindow = "reduceWinSize";
  10.             const string CommandIncreaseWindow = "increaseWinSize";
  11.             const string CommandInvertColors = "invertColors";
  12.             const string CommandChangePassword = "changePassword";
  13.             const string CommandClearScreen = "clear";
  14.             const string CommandExit = "exit";
  15.  
  16.             string userCommand;
  17.             string userInput;
  18.             string password = "admin";
  19.             int windowHeight = 16;
  20.             int windowWidth = 96;
  21.             bool isRunning = true;
  22.  
  23.             Console.SetWindowSize(windowWidth, windowHeight);
  24.             Console.WriteLine($"Список команд: {CommandReduceWindow}, {CommandIncreaseWindow}, {CommandInvertColors}, {CommandChangePassword}, {CommandClearScreen}, {CommandExit}");
  25.             Console.WriteLine($"Default password is \"{password}\"");
  26.  
  27.             while (isRunning)
  28.             {
  29.                 userCommand = Console.ReadLine();
  30.  
  31.                 switch (userCommand)
  32.                 {
  33.                     case CommandReduceWindow:
  34.                         windowHeight--;
  35.                         windowWidth--;
  36.                         Console.SetWindowSize(windowWidth, windowHeight);
  37.                         break;
  38.  
  39.                     case CommandIncreaseWindow:
  40.                         windowHeight++;
  41.                         windowWidth++;
  42.                         Console.SetWindowSize(windowWidth, windowHeight);
  43.                         break;
  44.  
  45.                     case CommandInvertColors:
  46.                         ConsoleColor consoleColor = Console.BackgroundColor;
  47.                         Console.BackgroundColor = Console.ForegroundColor;
  48.                         Console.ForegroundColor = consoleColor;
  49.                         break;
  50.  
  51.                     case CommandChangePassword:
  52.                         Console.Write("Введите старый пароль: ");
  53.                         userInput = Console.ReadLine();
  54.  
  55.                         if (userInput == password)
  56.                         {
  57.                             Console.Write("Введите новый пароль: ");
  58.                             password = Console.ReadLine();
  59.                             Console.WriteLine("Пароль успешно изменён.");
  60.                         }
  61.                         else
  62.                         {
  63.                             Console.WriteLine("Неверно введён пароль.");
  64.                         }
  65.                         break;
  66.  
  67.                     case CommandClearScreen:
  68.                         Console.Clear();
  69.                         break;
  70.  
  71.                     case CommandExit:
  72.                         isRunning = false;
  73.                         break;
  74.  
  75.                     default:
  76.                         Console.WriteLine("Неизвестная команда.");
  77.                         break;
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement