Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace Lesson2
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. const string Riddle = "\"Транспорт, который везет двух незнакомых соседей на восток без водителя за рулем\"";
  11. const string CorrectAnswer = "троллейбус";
  12. const string GiveUpWord = "сдаюсь";
  13. int maxAttempts = 3;
  14. int currentAttempt = 0;
  15. string userAnswer;
  16.  
  17. Console.WriteLine($"Привет! Давай поиграем в игру? Я загадал загадку.\n" +
  18. $"Попробуй отгадать ее. Количество попыток {maxAttempts}.\n" +
  19. $"Загадка:\n" +
  20. $"{Riddle}");
  21.  
  22. bool quite;
  23. do
  24. {
  25. Console.Write("Введи свой ответ: ");
  26.  
  27. userAnswer = Console.ReadLine().ToLower();
  28. currentAttempt++;
  29.  
  30. switch (userAnswer)
  31. {
  32. case CorrectAnswer:
  33. Console.WriteLine("Правильно!");
  34. quite = true;
  35. break;
  36. case GiveUpWord:
  37. Console.WriteLine($"Правильный ответ: {CorrectAnswer}.");
  38. quite = true;
  39. break;
  40. default:
  41. if (currentAttempt != maxAttempts)
  42. {
  43. Console.WriteLine("Подумай еще.");
  44. quite = false;
  45. }
  46. else
  47. {
  48. Console.WriteLine("Это была последняя попытка, и ты не угадал. Конец игре.");
  49. quite = true;
  50. }
  51. break;
  52. }
  53. } while (!quite);
  54.  
  55. Console.ReadLine();
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement