lovelyvook

Unit_11

Mar 31st, 2024 (edited)
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ijunior
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const string CommandCreateName = "1";
  10.             const string CommandGuessNumber = "2";
  11.             const string CommandClearConsole = "3";
  12.             const string CommandExit = "4";
  13.  
  14.             bool isWork = true;
  15.             string userInput;
  16.             string userName;
  17.             string userPassword;
  18.  
  19.             Random random = new Random();
  20.             int minRandomNumber = 1;
  21.             int maxRandomNumber = 10;
  22.             int totalAttempts = 3;
  23.             int restOfAttemps;
  24.  
  25.             while (isWork)
  26.             {
  27.                 Console.WriteLine($"{CommandCreateName} - задать имя и пароль" +
  28.                     $"\n{CommandGuessNumber} - отгадать случайное число" +
  29.                     $"\n{CommandClearConsole} - очистить консоль" +
  30.                     $"\n{CommandExit} - выйти из программы");
  31.                 Console.Write("Введите номер меню: ");
  32.                 userInput = Console.ReadLine();
  33.  
  34.                 switch (userInput)
  35.                 {
  36.                     case CommandCreateName:
  37.                         Console.Write("Введите имя: ");
  38.                         userName = Console.ReadLine();
  39.  
  40.                         Console.Write("Введите пароль: ");
  41.                         userPassword = Console.ReadLine();
  42.  
  43.                         Console.Write("Введите пароль, чтобы узнать секрет: ");
  44.                         userInput = Console.ReadLine();
  45.  
  46.                         if (userInput == userPassword)
  47.                         {
  48.                             Console.WriteLine(userName + ", ты сладкая булочка <3");
  49.                         }
  50.                         else
  51.                         {
  52.                             Console.WriteLine("Неверно");
  53.                         }
  54.                         break;
  55.  
  56.                     case CommandGuessNumber:
  57.                         restOfAttemps = totalAttempts;
  58.  
  59.                         for (int i = 0; i < totalAttempts; i++)
  60.                         {                            
  61.                             int randomNumber = random.Next(minRandomNumber, maxRandomNumber);
  62.                             Console.WriteLine($"Отгадай число между {minRandomNumber} и {maxRandomNumber}, у тебя {restOfAttemps} попыток");
  63.                             userInput = Console.ReadLine();
  64.  
  65.                             restOfAttemps--;
  66.  
  67.                             if (userInput == Convert.ToString(randomNumber))
  68.                             {
  69.                                 Console.WriteLine("Отличная работа!");
  70.                                 break;
  71.                             }
  72.                             else if (restOfAttemps == 0)
  73.                             {
  74.                                 Console.WriteLine("Повезет в следуюший раз");
  75.                             }
  76.                         }
  77.                         break;
  78.  
  79.                     case CommandClearConsole:
  80.                         Console.Clear();
  81.                         break;
  82.  
  83.                     case CommandExit:
  84.                         isWork = false;
  85.                         break;
  86.                 }
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment