Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. namespace cSharp
  2. {
  3.  
  4.     class TestSoft
  5.     {
  6.  
  7.         public static void ClearBuf(int currentp)
  8.         {
  9.             System.Console.CursorLeft = 0;
  10.             System.Console.CursorTop = currentp -1;
  11.         }
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             Console.WriteLine("Тест переключалки");
  16.             Start:
  17.             Console.Write($"\nВведите символ 1: ");
  18.             int symbol = 0;
  19.             int currentPosition = 0;
  20.             try
  21.             {
  22.                 symbol = Convert.ToInt32(Console.ReadLine());
  23.             }
  24.             catch (Exception)
  25.             {
  26.                 Console.WriteLine("Вы ввели букву! Введите символ!");
  27.                 goto Start;
  28.             }
  29.             if (symbol != 1)
  30.             {
  31.                 Console.WriteLine("Вы ввели не цифру 1! Введите цифру 1!");
  32.                 goto Start;
  33.             }
  34.             currentPosition = Console.CursorTop;
  35.             Console.WriteLine($"\nПоздравляем! Ваша цифра {symbol}!))");
  36.             Console.WriteLine("\nПовторить выполнение?");
  37.             Console.WriteLine("[Да]");
  38.             Console.WriteLine("Нет");
  39.  
  40.             bool WhileCycle = true;
  41.             bool ExitFlag = false;
  42.  
  43.             while (WhileCycle)
  44.             {
  45.                 ConsoleKeyInfo ck = Console.ReadKey();
  46.                 switch (ck.Key)
  47.                 {
  48.                     case ConsoleKey.DownArrow:
  49.                         Console.CursorVisible = false;
  50.                         ClearBuf(currentPosition);
  51.                         Console.ForegroundColor = ConsoleColor.Red;
  52.                         Console.Write($"\nВведите символ 1: {symbol}");
  53.                         Console.WriteLine($"\nПоздравляем! Ваша цифра {symbol}!))");
  54.                         Console.WriteLine("\nПовторить выполнение?");
  55.                         Console.WriteLine("Да");
  56.                         Console.WriteLine("[Нет]");
  57.                         ExitFlag = true;
  58.  
  59.                         break;
  60.  
  61.                     case ConsoleKey.UpArrow:
  62.  
  63.                         Console.CursorVisible = false;
  64.                         ClearBuf(currentPosition);
  65.                         Console.ForegroundColor = ConsoleColor.Green;
  66.                         Console.Write($"\nВведите символ 1: {symbol}");
  67.                         Console.WriteLine($"\nПоздравляем! Ваша цифра {symbol}!))");
  68.                         Console.WriteLine("\nПовторить выполнение?");
  69.                         Console.WriteLine("[Да]");
  70.                         Console.WriteLine("Нет");
  71.                         ExitFlag = false;
  72.                         break;
  73.  
  74.                     case ConsoleKey.Enter:
  75.                         if (ExitFlag)
  76.                         { WhileCycle = false; }
  77.  
  78.                         else
  79.                         {
  80.                             Console.Clear();
  81.                             goto Start;
  82.                         }
  83.                         break;
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement