Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ijunior
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandCreateName = "1";
- const string CommandGuessNumber = "2";
- const string CommandClearConsole = "3";
- const string CommandExit = "4";
- bool isWork = true;
- string userInput;
- string userName;
- string userPassword;
- Random random = new Random();
- int minRandomNumber = 1;
- int maxRandomNumber = 10;
- int totalAttempts = 3;
- int restOfAttemps;
- while (isWork)
- {
- Console.WriteLine($"{CommandCreateName} - задать имя и пароль" +
- $"\n{CommandGuessNumber} - отгадать случайное число" +
- $"\n{CommandClearConsole} - очистить консоль" +
- $"\n{CommandExit} - выйти из программы");
- Console.Write("Введите номер меню: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandCreateName:
- Console.Write("Введите имя: ");
- userName = Console.ReadLine();
- Console.Write("Введите пароль: ");
- userPassword = Console.ReadLine();
- Console.Write("Введите пароль, чтобы узнать секрет: ");
- userInput = Console.ReadLine();
- if (userInput == userPassword)
- {
- Console.WriteLine(userName + ", ты сладкая булочка <3");
- }
- else
- {
- Console.WriteLine("Неверно");
- }
- break;
- case CommandGuessNumber:
- restOfAttemps = totalAttempts;
- for (int i = 0; i < totalAttempts; i++)
- {
- int randomNumber = random.Next(minRandomNumber, maxRandomNumber);
- Console.WriteLine($"Отгадай число между {minRandomNumber} и {maxRandomNumber}, у тебя {restOfAttemps} попыток");
- userInput = Console.ReadLine();
- restOfAttemps--;
- if (userInput == Convert.ToString(randomNumber))
- {
- Console.WriteLine("Отличная работа!");
- break;
- }
- else if (restOfAttemps == 0)
- {
- Console.WriteLine("Повезет в следуюший раз");
- }
- }
- break;
- case CommandClearConsole:
- Console.Clear();
- break;
- case CommandExit:
- isWork = false;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment