Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Hangman
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] hangMen = {" +-----+" +
  14. "\n O\t|" +
  15. "\n /|\\ \t|" +
  16. "\n / \\ \t|" +
  17. "\n ===",
  18. " +-----+" +
  19. "\n O\t|" +
  20. "\n /|\\ \t|" +
  21. "\n \t|" +
  22. "\n ===",
  23. " +-----+" +
  24. "\n O\t|" +
  25. "\n | \t|" +
  26. "\n \t|" +
  27. "\n ===",
  28. " +-----+" +
  29. "\n O\t|" +
  30. "\n \t|" +
  31. "\n \t|" +
  32. "\n ===",
  33. " +-----+" +
  34. "\n \t|" +
  35. "\n \t|" +
  36. "\n \t|" +
  37. "\n ===",
  38. "\n \t|" +
  39. "\n \t|" +
  40. "\n \t|" +
  41. "\n ===",
  42. "\n ===",
  43. ""
  44.  
  45. };
  46. int lives = 7;
  47. string[] words = { "airplane", "car", "train", "bus", "bycicle", "motorcycle", "helicopter", "boat" };
  48. Random rnd = new Random();
  49. int num = rnd.Next(1, 8);
  50. string word = words[num];
  51. int length = word.Length;
  52. char[] letters = word.ToCharArray();
  53. List<string> blanks = new List<string>();
  54. int x = 0;
  55. while(x<length)
  56. {
  57. blanks.Add("_");
  58. x += 1;
  59. }
  60. int correct = 0;
  61. List<string> right = new List<string>();
  62. List<string> wrong = new List<string>();
  63. List<string> guessed = new List<string>();
  64. do
  65. {
  66. foreach(var i in blanks)
  67. {
  68. Console.Write(i);
  69. }
  70. Console.WriteLine();
  71. Console.WriteLine("You have {0} guess(es) remaining.", lives);
  72. Console.WriteLine(hangMen[lives]);
  73. Console.WriteLine("Enter a letter:");
  74. string guess = Console.ReadLine();
  75. if (word.Contains(guess))
  76. {
  77. Console.WriteLine("{0} is in the word!", guess);
  78. guessed.Add(guess);
  79. right.Add(guess);
  80. correct += 1;
  81. }
  82. else if (guessed.Contains(guess))
  83. {
  84. Console.WriteLine("{0} has already been guessed.", guess);
  85. }
  86. else
  87. {
  88. Console.WriteLine("{0} isn't in the word.", guess);
  89. guessed.Add(guess);
  90. wrong.Add(guess);
  91. lives -= 1;
  92. }
  93. int y = 0;
  94. foreach (var item in letters)
  95. {
  96. string itemString = item.ToString();
  97. if (guess == itemString)
  98. {
  99. blanks[y] = guess;
  100. }
  101. y += 1;
  102. }
  103. if (blanks.Contains("_"))
  104. {
  105.  
  106. }
  107. else
  108. {
  109. Console.WriteLine("You guessed it, the word was {0}.", word);
  110. lives = -1;
  111. }
  112. } while (lives > 0);
  113. if (lives == 0)
  114. {
  115. Console.WriteLine(hangMen[lives]);
  116. Console.WriteLine("You failed, the word was {0}.", word);
  117. }
  118. else if (lives == -1)
  119. {
  120.  
  121. }
  122. Console.ReadLine();
  123.  
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement