holllowknight

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

Mar 7th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 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 ConsoleMenu
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string userCommand;
  14.             int winHeight = 16;
  15.             int winWidth = 96;
  16.             bool backgroundIsBlack = true;
  17.             string password = "admin";
  18.  
  19.             Console.SetWindowSize(winWidth, winHeight);
  20.             Console.WriteLine("Список команд: reduceWinSize, increaseWinSize, invertColors, changePassword, clear, esc");
  21.             Console.WriteLine($"Default password is {password}");
  22.             string userInput;
  23.  
  24.             while (true)
  25.             {
  26.                 userCommand = Console.ReadLine();
  27.  
  28.                 switch (userCommand)
  29.                 {
  30.                     case "reduceWinSize":
  31.                         winHeight--;
  32.                         winWidth--;
  33.                         Console.SetWindowSize(winWidth, winHeight);
  34.                         break;
  35.                     case "increaseWinSize":
  36.                         winHeight++;
  37.                         winWidth++;
  38.                         Console.SetWindowSize(winWidth, winHeight);
  39.                         break;
  40.                      case "invertColors":
  41.                         backgroundIsBlack = !backgroundIsBlack;
  42.                         if (backgroundIsBlack)
  43.                         {
  44.                             Console.BackgroundColor = ConsoleColor.Black;
  45.                             Console.ForegroundColor = ConsoleColor.White;
  46.                         }
  47.                         else
  48.                         {
  49.                             Console.BackgroundColor = ConsoleColor.White;
  50.                             Console.ForegroundColor = ConsoleColor.Black;
  51.                         }
  52.                          break;
  53.                      case "changePassword":
  54.                         Console.Write("Введите старый пароль: ");
  55.                         userInput = Console.ReadLine();
  56.                         if(userInput == password)
  57.                         {
  58.                             Console.Write("Введите новый пароль: ");
  59.                             password = Console.ReadLine();
  60.                             Console.WriteLine("Пароль успешно изменён.");
  61.                         }
  62.                         else
  63.                         {
  64.                             Console.WriteLine("Неверно введён пароль.");
  65.                         }
  66.                          break;
  67.                      case "clear":
  68.                         Console.Clear();
  69.                          break;
  70.                     case "esc":
  71.                         return;
  72.                     default:
  73.                         Console.WriteLine("Неизвестная команда.");
  74.                         break;
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
Add Comment
Please, Sign In to add comment