Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. /*Ashley Jerome
  2. Project 1
  3. Part 4
  4. Interactive Hangman application that displays a gradually hanging man.
  5. 10/25/10
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. /*needed for strcpy in randWord function for assigning
  11. strings to arrays*/
  12. #include <string.h>
  13.  
  14. /*function prototype definitions*/
  15. void randWord(int);
  16. void enterGuess();
  17. void checkGuess(char);
  18.  
  19. void hangMan(int);
  20.  
  21. int i;
  22. int wrong=0;
  23. int correct=0;
  24. //word to be guessed
  25. char guessed[7]={'*','*','*','*','*','*','*'};
  26. //stored word
  27. char word[7];
  28. //current guess
  29. char guess;
  30. //already guessed letter
  31. char guesses[25];
  32.  
  33.  
  34. void main()
  35. {
  36. randWord(i);
  37. printf("Welcome to Hangman!\n");
  38. //scanf("%c", &guess);
  39. //hangMan(wrong);
  40. //checkGuess(guess);
  41. while(correct <= 7)
  42. {
  43. if (&guess!=NULL)
  44. {
  45. enterGuess();
  46. }
  47. checkGuess(guess);
  48. }
  49. printf("\nYou win!\n");
  50.  
  51.  
  52.  
  53. }
  54. /*creates a random number and assigns it to a word which is stored in an array*/
  55. void randWord(int i)
  56. {
  57. srand(time(NULL));
  58.  
  59. int max=9;
  60. int min=0;
  61.  
  62. //determine a random number for a word for Hangman
  63. correct=random()%((max+1)-min)+min;
  64.  
  65. switch(correct)
  66. {
  67. case 0: {strcpy(word, "postfix");
  68. break;}
  69. case 1: {strcpy(word, "integer");
  70. break;}
  71. case 2: {strcpy(word, "process");
  72. break;}
  73. case 3: {strcpy(word, "comment");
  74. break;}
  75. case 4: {strcpy(word, "program");
  76. break;}
  77. case 5: {strcpy(word, "command");
  78. break;}
  79. case 6: {strcpy(word, "compute");
  80. break;}
  81. case 7: {strcpy(word, "logical");
  82. break;}
  83. case 8: {strcpy(word, "compile");
  84. break;}
  85. case 9: {strcpy(word, "pointer");
  86. break;}
  87. }
  88. }
  89. /*void isGuessed(char a)
  90. {
  91. int i;
  92. for(int i=0; i<25; i++)
  93. {
  94. if(a==guesses[i])
  95. {
  96. printf("You already guessed %c. Enter another letter.\n");
  97. }else
  98. }
  99. }*/
  100. void checkGuess(char a)
  101. {
  102. int i;
  103. int j;
  104. for (i=0; i<7; i++)
  105. {
  106. if(a==word[i])
  107. {
  108. guessed[i]=a;
  109. correct++;
  110. }
  111. }
  112. //output
  113. for (j=0; j<7; j++)
  114. {
  115. printf("%c", guessed[j]);
  116. }
  117. }
  118.  
  119. void enterGuess()
  120. {
  121. printf("\nEnter your guess.\n");
  122. scanf("%c", &guess);
  123. //checkGuess(guess);
  124. }
  125. void hangMan(int i)
  126. {
  127. switch(i)
  128. {
  129. //print empty hangman noose
  130. case 0:{printf(" ___________\n | / |\n |\n |\n |\n |\n |\n_|___");}
  131. //print hangman noose with a head
  132. case 1:{printf(" ___________\n | / |\n | (_)\n |\n |\n |\n |\n_|___");}
  133. //print hangman noose with head, and body
  134. case 2:{printf(" ___________\n | / |\n | (_)\n | |\n | |\n |\n |\n_|___");}
  135. //print hangman noose with head, body, and arm
  136. case 3:{printf(" ___________\n | / |\n | (_)\n | \\|\n | |\n |\n |\n_|___");}
  137. //print hangman noose with head, body, and 2 arms
  138. case 4:{printf(" ___________\n | / |\n | (_)\n | \\|/\n | |\n |\n |\n_|___");}
  139. //print hangman noose with head, body, 2 arms, and leg
  140. case 5:{printf(" ___________\n | / |\n | (_)\n | \\|/\n | |\n | /\n |\n_|___");}
  141. //print hangman noose with head, body, 2 arms, and 2 legs
  142. case 6:{printf(" ___________\n | / |\n | (_)\n | \\|/\n | |\n | / \\\n |\n_|___");}
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement