Advertisement
Guest User

C# Hangman

a guest
Mar 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 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.  
  14.  
  15. string[] Hangman= {" +-----+" +
  16. "\n O\t|" +
  17. "\n /|\\ \t|" +
  18. "\n / \\ \t|" +
  19. "\n ===",
  20. " +-----+" +
  21. "\n O\t|" +
  22. "\n /|\\ \t|" +
  23. "\n \t|" +
  24. "\n ===",
  25. " +-----+" +
  26. "\n O\t|" +
  27. "\n | \t|" +
  28. "\n \t|" +
  29. "\n ===",
  30. " +-----+" +
  31. "\n O\t|" +
  32. "\n \t|" +
  33. "\n \t|" +
  34. "\n ===",
  35. " +-----+" +
  36. "\n \t|" +
  37. "\n \t|" +
  38. "\n \t|" +
  39. "\n ===",
  40. "\n \t|" +
  41. "\n \t|" +
  42. "\n \t|" +
  43. "\n ===",
  44. "\n ===",
  45. ""
  46.  
  47. };
  48. int lives = 7;
  49. string[] Words = { "tiger", "leopard", "lion", "owl", "penguin", "wolf", "bear", "monkey", "cow", "pig", "dog", "cat" };
  50. Random randNum = new Random();
  51. int number = randNum.Next(1, 12);
  52. string target = Words[number];
  53. int len = target.Length;
  54. char[] characters = target.ToCharArray();
  55. List<string> blankspaces = new List<string>();
  56. List<string> guessedLetters = new List<string>();
  57. List<string> correct = new List<string>();
  58. double correctLetters = 0;
  59. int blanks = 0;
  60. while (blanks < 0)
  61. {
  62. blankspaces.Add("_");
  63. blanks += 1;
  64. }
  65. do
  66. {
  67. foreach (var i in blankspaces)
  68. {
  69. Console.Write(i);
  70. }
  71. Console.WriteLine();
  72. Console.WriteLine("Lives: {0}", lives);
  73. Console.WriteLine(Hangman[lives]);
  74. Console.WriteLine("Enter a letter to guess: ");
  75. string playerGuess = Console.ReadLine();
  76.  
  77. if (guessedLetters.Contains(playerGuess))
  78. {
  79. Console.WriteLine("You already guessed that letter");
  80. }
  81. else if (target.Contains(playerGuess))
  82. {
  83. Console.WriteLine("Your letter is in the word!");
  84. guessedLetters.Add(playerGuess);
  85. correct.Add(playerGuess);
  86. correctLetters += 1;
  87. }
  88. else
  89. {
  90. Console.WriteLine("Your letter isn't in the word.");
  91. guessedLetters.Add(playerGuess);
  92. lives -= 1;
  93. }
  94. if (len != correctLetters)
  95. {
  96.  
  97. }
  98. else
  99. {
  100. Console.WriteLine("Well done! The target word was {0}.", target);
  101. lives = -1;
  102. }
  103. } while (lives > 0);
  104. if (lives == 0)
  105. {
  106. Console.WriteLine(Hangman[lives]);
  107. Console.WriteLine("You ran out of lives. The target word was {0}.", target);
  108. }
  109. else if (lives == -1)
  110. {
  111.  
  112. }
  113. Console.ReadLine();
  114.  
  115.  
  116.  
  117.  
  118.  
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement