Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. class Program
  9. {
  10. static List<String> Words { get; set; }
  11. static Int32 GuessCount { get; set; }
  12.  
  13. static void Main(string[] args)
  14. {
  15. Words = new List<String>();
  16. DrawMenu();
  17. }
  18.  
  19. static void DrawMenu()
  20. {
  21. Console.Clear();
  22.  
  23. Console.WriteLine("1. Lägg till.");
  24. Console.WriteLine("2. Visa alla.");
  25. Console.WriteLine("3. Spela.");
  26. Console.WriteLine("4. Avsluta.");
  27.  
  28. switch (Console.ReadKey().Key)
  29. {
  30. case ConsoleKey.D1:
  31. AddWord();
  32. break;
  33.  
  34. case ConsoleKey.D2:
  35. DisplayWords();
  36. break;
  37.  
  38. case ConsoleKey.D3:
  39. Play();
  40. break;
  41.  
  42. case ConsoleKey.D4:
  43. Exit();
  44. break;
  45.  
  46. default:
  47. DrawMenu();
  48. break;
  49. }
  50. }
  51.  
  52. static void AddWord()
  53. {
  54. Console.Clear();
  55. Console.WriteLine("Skriv ett ord och tryck på enter:");
  56. Words.Add(Console.ReadLine());
  57. Console.WriteLine();
  58.  
  59. Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
  60. Console.ReadKey();
  61. DrawMenu();
  62. }
  63.  
  64. static void DisplayWords()
  65. {
  66. Console.Clear();
  67. Console.WriteLine("Dessa ord är tillagda:");
  68. foreach (String word in Words)
  69. {
  70. Console.WriteLine(word);
  71. }
  72. Console.WriteLine();
  73.  
  74. Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
  75. Console.ReadKey();
  76. DrawMenu();
  77. }
  78.  
  79. static void Play()
  80. {
  81. String randomWord = Words.OrderBy(x => Guid.NewGuid()).First();
  82. String guessWord = String.Empty;
  83.  
  84. GuessCount = 0;
  85.  
  86. Console.Clear();
  87. Console.WriteLine("Gissa vilket ord:");
  88.  
  89. while (guessWord.ToLower() != randomWord.ToLower())
  90. {
  91. guessWord = Console.ReadLine();
  92.  
  93. if (guessWord.ToLower() != randomWord.ToLower())
  94. {
  95. GuessCount++;
  96.  
  97. Console.WriteLine(String.Format("Du har gissat fel {0} gånger.", GuessCount));
  98. }
  99. }
  100.  
  101. Console.WriteLine("Du gissade rätt.");
  102.  
  103. Console.WriteLine("Tryck valfri knapp för att gå till menyn.");
  104. Console.ReadKey();
  105. DrawMenu();
  106. }
  107.  
  108. static void Exit()
  109. {
  110. Console.Clear();
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement