Abdula_2314124

Untitled

Apr 14th, 2024
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. namespace Fproject
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             string[] questions =
  8.             {
  9.                 "Юніті vs Unreal?",
  10.                 "int vs float?",
  11.                 "Львівське Різдвяне vs Балтіка?",
  12.                 "A vs B?"
  13.             };
  14.             string[] rightAnswers =
  15.             {
  16.                 "Unity",
  17.                 "inteFLoat",
  18.                 "Lvivske",
  19.                 "AB"
  20.             };
  21.  
  22.             Random rnd = new Random();
  23.             var index = rnd.Next(0, questions.Length);
  24.             Game(questions, rightAnswers, rnd, index);
  25.  
  26.         }
  27.  
  28.         static void Game(string[] questions, string[] rightAnswers, Random rnd, int index)
  29.         {
  30.             while (true)
  31.             {
  32.                 Console.WriteLine(questions[index]);
  33.                 int prevIndex = index;
  34.                 string userAnswer = Console.ReadLine();
  35.                 CheckRightIndex(rightAnswers, rnd, index, userAnswer);
  36.                 index = UpdateIndex(questions, rnd, index, prevIndex);
  37.             }
  38.         }
  39.  
  40.         static void CheckRightIndex(string[] rightAnswers, Random rnd, int index, string userAnswer)
  41.         {
  42.             if (rightAnswers[index].Equals(userAnswer))
  43.             {
  44.                 Console.ForegroundColor = ConsoleColor.Green;
  45.                 Console.WriteLine("GOOOD");
  46.                 Console.ResetColor();
  47.             }
  48.             else
  49.             {
  50.                 Console.ForegroundColor = ConsoleColor.Red;
  51.                 Console.WriteLine("BADDDDDDDDDD");
  52.                 Console.ResetColor();
  53.             }
  54.         }
  55.  
  56.         static int UpdateIndex(string[] questions, Random rnd, int index, int prevIndex)
  57.         {
  58.             while (index == prevIndex)
  59.             {
  60.                 index = rnd.Next(0, questions.Length);
  61.             }
  62.  
  63.             return index;
  64.         }
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment