Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lesson2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string login = "";
  10. string password = "";
  11. string charName = "";
  12. string charClass = "";
  13. ConsoleColor infoColor = ConsoleColor.White;
  14. char borderSymbol = ' ';
  15.  
  16. bool isLoginSet = false;
  17. bool isPasswordSet = false;
  18.  
  19. bool quit = false;
  20.  
  21. while (!quit)
  22. {
  23. string inputCommand = Console.ReadLine().ToLower();
  24. string userInput;
  25.  
  26. switch (inputCommand)
  27. {
  28. case "setlogin":
  29. Console.Write("Задайте свой логин (логин не может быть пустым или состоять из пробелов): ");
  30. userInput = Console.ReadLine();
  31.  
  32. if (string.IsNullOrWhiteSpace(userInput))
  33. {
  34. Console.WriteLine("Неверный формат, логин не может быть пустым или состоять из пробелов.");
  35. }
  36. else
  37. {
  38. login = userInput;
  39. isLoginSet = true;
  40. Console.WriteLine("Логин успешно задан");
  41. }
  42. break;
  43.  
  44. case "setpassword":
  45. if (isLoginSet)
  46. {
  47. Console.Write("Задайте свой пароль (пароль не может быть пустым или состоять из пробелов): ");
  48. userInput = Console.ReadLine();
  49.  
  50. if (string.IsNullOrWhiteSpace(userInput))
  51. {
  52. Console.WriteLine("Неверный формат, пароль не может быть пустым или состоять из пробелов.");
  53. }
  54. else
  55. {
  56. password = userInput;
  57. isPasswordSet = true;
  58. Console.WriteLine("Пароль успешно задан");
  59. }
  60. }
  61. else
  62. {
  63. Console.WriteLine("Не задан логин, для установки пароля необходимо задать логин.");
  64. }
  65.  
  66. break;
  67.  
  68. case "setname":
  69. Console.Write("Задайте имя вашего персонажа (имя не может быть пустым или состоять из пробелов): ");
  70. userInput = Console.ReadLine();
  71.  
  72. if (string.IsNullOrWhiteSpace(userInput))
  73. {
  74. Console.WriteLine("Неверный формат, имя не может быть пустым или состоять из пробелов");
  75. }
  76. else
  77. {
  78. charName = userInput;
  79. Console.WriteLine("Имя успешно задано");
  80. }
  81. break;
  82.  
  83. case "setclass":
  84. Console.WriteLine("Допустимые классы персонажа: варвар, колдун, некромант, амазонка, паладин.");
  85. Console.Write("Задайте класс вашего персонажа: ");
  86. userInput = Console.ReadLine().ToLower();
  87.  
  88. bool isCorrectInput = (userInput == "варвар") ||
  89. (userInput == "колдун") ||
  90. (userInput == "некромант") ||
  91. (userInput == "амазонка") ||
  92. (userInput == "паладин");
  93.  
  94. if (isCorrectInput)
  95. {
  96. charClass = userInput;
  97. Console.WriteLine("Класс успешно задан");
  98. }
  99. else
  100. {
  101. Console.WriteLine("Неверный формат, допустимые классы персонажа: варвар, колдун, некромант, амазонка, паладин.");
  102. }
  103. break;
  104.  
  105. case "printinfo":
  106. Console.WriteLine("Для выполнения этой операции требуется ввести пароль: ");
  107. userInput = Console.ReadLine();
  108.  
  109. if (userInput == password)
  110. {
  111. ConsoleColor currentColor = Console.ForegroundColor;
  112. Console.ForegroundColor = infoColor;
  113.  
  114. string charInfo = $"Информация о персонаже\n\n" +
  115. $"Имя\t - {charName}\n" +
  116. $"Класс\t - {charClass}";
  117. string border = string.Empty.PadLeft(Console.WindowWidth, borderSymbol);
  118.  
  119. Console.WriteLine($"{border}\n" +
  120. $"{charInfo}\n\n" +
  121. $"{border}");
  122.  
  123. Console.ForegroundColor = currentColor;
  124. }
  125. else if (!isPasswordSet)
  126. {
  127. Console.WriteLine("Не задан пароль, установите пароль.");
  128. }
  129. else
  130. {
  131. Console.WriteLine("Введен неправильный пароль, доступ к информации невозможен.");
  132. }
  133. break;
  134.  
  135. case "setbordersymbol":
  136. Console.Write("Задайте символ рамки: ");
  137.  
  138. borderSymbol = Convert.ToChar(Console.Read());
  139. Console.ReadLine();
  140. break;
  141.  
  142. case "setinfocolor":
  143. Console.WriteLine($"Допустимые цвета текста: {ConsoleColor.Blue}, {ConsoleColor.Gray}, {ConsoleColor.Green}, " +
  144. $"{ConsoleColor.Magenta}, {ConsoleColor.Red}, {ConsoleColor.Cyan}, {ConsoleColor.White}, {ConsoleColor.Yellow}");
  145. Console.Write("Задайте цвет текста информации о персонаже: ");
  146. userInput = Console.ReadLine().ToLower();
  147. switch (userInput)
  148. {
  149. case "blue":
  150. infoColor = ConsoleColor.Blue;
  151. break;
  152. case "gray":
  153. infoColor = ConsoleColor.Gray;
  154. break;
  155. case "green":
  156. infoColor = ConsoleColor.Green;
  157. break;
  158. case "magenta":
  159. infoColor = ConsoleColor.Magenta;
  160. break;
  161. case "red":
  162. infoColor = ConsoleColor.Red;
  163. break;
  164. case "cyan":
  165. infoColor = ConsoleColor.Cyan;
  166. break;
  167. case "white":
  168. infoColor = ConsoleColor.White;
  169. break;
  170. case "yellow":
  171. infoColor = ConsoleColor.Yellow;
  172. break;
  173. default:
  174. Console.WriteLine("Не вводи что попало!");
  175. break;
  176. }
  177. break;
  178.  
  179. case "settextcolor":
  180. Console.WriteLine($"Допустимые цвета текста: {ConsoleColor.Blue}, {ConsoleColor.Gray}, {ConsoleColor.Green}, {ConsoleColor.Magenta}, " +
  181. $"{ConsoleColor.Red}, {ConsoleColor.Cyan}, {ConsoleColor.White}, {ConsoleColor.Yellow}");
  182. Console.Write("Задайте цвет текста консоли: ");
  183. userInput = Console.ReadLine().ToLower();
  184. //Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), userInput, true);
  185. switch (userInput)
  186. {
  187. case "blue":
  188. Console.ForegroundColor = ConsoleColor.Blue;
  189. break;
  190. case "gray":
  191. Console.ForegroundColor = ConsoleColor.Gray;
  192. break;
  193. case "green":
  194. Console.ForegroundColor = ConsoleColor.Green;
  195. break;
  196. case "magenta":
  197. Console.ForegroundColor = ConsoleColor.Magenta;
  198. break;
  199. case "red":
  200. Console.ForegroundColor = ConsoleColor.Red;
  201. break;
  202. case "cyan":
  203. Console.ForegroundColor = ConsoleColor.Cyan;
  204. break;
  205. case "white":
  206. Console.ForegroundColor = ConsoleColor.White;
  207. break;
  208. case "yellow":
  209. Console.ForegroundColor = ConsoleColor.Yellow;
  210. break;
  211. default:
  212. Console.WriteLine("Не вводи что попало!");
  213. break;
  214. }
  215. break;
  216.  
  217. case "help":
  218. Console.WriteLine("Список доступных команд:\n" +
  219. "setlogin\t - задать логин\n" +
  220. "setpassword\t - задать пароль\n" +
  221. "setname\t\t - задать имя персонажа\n" +
  222. "setclass\t - задать класс персонажа\n" +
  223. "printinfo\t - вывести информацию\n" +
  224. "setbordersymbol\t - задать символ рамки\n" +
  225. "setinfocolor\t - задать цвет текста информации о персонаже\n" +
  226. "settextcolor\t - задать цвет текста консоли\n" +
  227. "help\t\t - вывести список команд\n" +
  228. "esc\t\t - выход\n");
  229. break;
  230.  
  231. case "esc":
  232. Environment.Exit(0);
  233. break;
  234.  
  235. default:
  236. Console.WriteLine("Для просмотра допустимых команд наберите \"help\"");
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement