morry2341

Hangman

Oct 21st, 2022 (edited)
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace DemoHangman
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int amountOfLettersRevealed = 0;
  14. int minusPoints = 0;
  15. Console.WriteLine("Welcome to Hangman!!!!!!!!!!");
  16. Console.InputEncoding = Encoding.Default;
  17. string[] listwords = File.ReadAllLines(@"/Users/annamusterfrau/Desktop/C#_co/italian.txt");
  18. Random randGen = new Random();
  19. var idx = randGen.Next(0, 9);
  20. string mysteryWord = listwords[idx];
  21. char[] hangman = new char[mysteryWord.Length];
  22. Console.Write("Please enter your guess: ");
  23.  
  24. for (int p = 0; p < mysteryWord.Length; p++)
  25. {
  26. hangman[p] = '*';
  27.  
  28. }
  29.  
  30. while (true)
  31. {
  32. string playerGuess;
  33. string charLength = string.Empty;
  34.  
  35. playerGuess = Console.ReadLine();
  36. char guessed = playerGuess[0];
  37.  
  38. if (playerGuess.Length > 1)
  39. {
  40. int count = 0;
  41. for (int i = 0; i < playerGuess.Length; i++)
  42. {
  43. if (playerGuess[0] == playerGuess[i])
  44. {
  45. count++;
  46. }
  47. }
  48.  
  49. charLength += playerGuess[0] + count;
  50. if (charLength.Length > 1)
  51. {
  52. Console.WriteLine("enter only one char at a time");
  53. }
  54. }
  55.  
  56. if (!mysteryWord.Contains(guessed))
  57. {
  58. minusPoints++;
  59. }
  60. for (int j = 0; j < mysteryWord.Length; j++)
  61. {
  62. if (guessed == mysteryWord[j])
  63. {
  64. hangman[j] = guessed;
  65. amountOfLettersRevealed++;
  66.  
  67. }
  68.  
  69.  
  70. }
  71. Console.WriteLine(hangman);
  72.  
  73. if (hangman.Length == amountOfLettersRevealed)
  74. {
  75. Console.WriteLine("hip hip hooray, you got it all right!");
  76. Console.WriteLine("your total minus point is: " + minusPoints);
  77. }
  78.  
  79.  
  80.  
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment