AdemDev

Консольное меню

Aug 30th, 2023 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. const string CreateNewPasswordCommand = "new password";
  10. const string ShowPrivateInformationCommand = "private information";
  11. const string ChangeBackgroundColourCommand = "change background colour";
  12. const string ChangeFontColourCommand = "change font colour";
  13. const string ExitCommand = "exit";
  14.  
  15. string redColourName = "красный";
  16. string blueColourName = "синий";
  17. string whiteColourName = "белый";
  18. string grayColourName = "серый";
  19. string greenColourName = "зеленый";
  20.  
  21. string password = "0000";
  22. bool isProgramActive = true;
  23.  
  24. Console.WriteLine($"Доступные команды:\n{CreateNewPasswordCommand}\n{ShowPrivateInformationCommand}\n{ChangeBackgroundColourCommand}\n{ChangeFontColourCommand}\n{ExitCommand}\n");
  25.  
  26. while (isProgramActive)
  27. {
  28. Console.Write("Введите команду: ");
  29. string command = Console.ReadLine();
  30.  
  31. switch (command)
  32. {
  33. case CreateNewPasswordCommand:
  34. Console.Write("Введите текущий пароль: ");
  35. string userInput = Console.ReadLine();
  36.  
  37. if (userInput == password)
  38. {
  39. Console.Write("Введите новый пароль: ");
  40. password = Console.ReadLine();
  41. Console.WriteLine("Пароль успешно изменен!\n");
  42. }
  43. else
  44. {
  45. Console.WriteLine("Введен неверный пароль!\n");
  46. }
  47. break;
  48.  
  49. case ShowPrivateInformationCommand:
  50. Console.Write("Введите текущий пароль: ");
  51. userInput = Console.ReadLine();
  52.  
  53. if (userInput == password)
  54. {
  55. Console.WriteLine("Приватная информация\n");
  56. }
  57. else
  58. {
  59. Console.WriteLine("Введен неверный пароль!\n");
  60. }
  61. break;
  62.  
  63. case ChangeBackgroundColourCommand:
  64. Console.WriteLine("Какой цвет ты хочешь установить?");
  65. userInput = Console.ReadLine();
  66.  
  67. if (userInput == redColourName)
  68. {
  69. Console.BackgroundColor = ConsoleColor.Red;
  70. }
  71. else if (userInput == blueColourName)
  72. {
  73. Console.BackgroundColor = ConsoleColor.Blue;
  74. }
  75. else if (userInput == whiteColourName)
  76. {
  77. Console.BackgroundColor = ConsoleColor.White;
  78. }
  79. else if (userInput == grayColourName)
  80. {
  81. Console.BackgroundColor = ConsoleColor.Gray;
  82. }
  83. else if (userInput == greenColourName)
  84. {
  85. Console.BackgroundColor = ConsoleColor.Green;
  86. }
  87. Console.Clear();
  88. break;
  89.  
  90. case ChangeFontColourCommand:
  91. Console.WriteLine("Какой цвет ты хочешь установить?");
  92. userInput = Console.ReadLine();
  93.  
  94. if (userInput == redColourName)
  95. {
  96. Console.ForegroundColor = ConsoleColor.Red;
  97. }
  98. else if (userInput == blueColourName)
  99. {
  100. Console.ForegroundColor = ConsoleColor.Blue;
  101. }
  102. else if (userInput == whiteColourName)
  103. {
  104. Console.ForegroundColor = ConsoleColor.White;
  105. }
  106. else if (userInput == grayColourName)
  107. {
  108. Console.ForegroundColor = ConsoleColor.Gray;
  109. }
  110. else if (userInput == greenColourName)
  111. {
  112. Console.ForegroundColor = ConsoleColor.Green;
  113. }
  114. break;
  115.  
  116. case ExitCommand:
  117. isProgramActive = false;
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment