Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. //This program features:
  2. // 1) A sound effect when the player guess a right or wrong letter
  3. // 2) In this game program, the player has 6 chances to guess wrong
  4. // 3) There is an option to replay the game when the game ends
  5. // 4a) During the game, the game features green colour when lives is more than half
  6. // 4b) During the game, the game features yellow colour when lives is half
  7. // 4c) During the game, the game features red colour when lives is less than half
  8. // 5) In this game program, the player can choose to enter their own word or get a random word
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <string.h>
  15.  
  16. // function prototypes
  17. void intro();
  18. void displayscreen();
  19. void answer();
  20. void hangman();
  21.  
  22. int key;
  23.  
  24. void main()
  25. {
  26. intro();
  27. answer();
  28. }
  29.  
  30. void intro()
  31. {
  32. system("COLOR B");
  33.  
  34. printf("\t\t\t\t\t Welcome to...\n\n");
  35. Sleep(1000);
  36. printf("\t\t\t## ## ###### ## ## ###### ## ## ###### ## ##\n");
  37. printf("\t\t\t## ## ## ## ### ## ## ## ### ### ## ## ### ##\n");
  38. printf("\t\t\t###### ## ## ## # ## ## ## # ## ## ## ## # ##\n");
  39. printf("\t\t\t###### ###### ## # ## ## ### ## # ## ###### ## # ##\n");
  40. printf("\t\t\t## ## ## ## ## ### ## ## ## ## ## ## ## ###\n");
  41. printf("\t\t\t## ## ## ## ## ## ###### ## ## ## ## ## ##\n");
  42. Sleep(1000);
  43. printf("\n\n\t\t\t\tIF YOU GUESS WRONG TOO MANY TIMES");
  44. Sleep(1000);
  45. system("COLOR 4");
  46. printf("\n\n\n\t\t\t\t\tYOU WILL BE HANGED");
  47. Sleep(1000);
  48. printf("\n\n\n\t\t\t\t\t Good Luck!");
  49. Sleep(1500);
  50.  
  51. printf("\n\n\n\n\n\nGame Instruction");
  52. printf("\n****************");
  53. printf("\nYou are given 6 attempts for your mistake guessing.\n");
  54. getche();
  55. }
  56.  
  57. void displayscreen()
  58. {
  59. printf("\n\t********************\n");
  60. printf("\t* *\n");
  61. printf("\t* Hangman *\n");
  62. printf("\t* *\n");
  63. printf("\t********************\n");
  64. }
  65.  
  66. void answer()
  67. {
  68. char guessed[30];
  69. char Word[2][20];
  70. char letter,pick;
  71. int i,attempt=0,n=0;
  72.  
  73.  
  74. strcpy(Word[1],"apple orange");
  75. strcpy(Word[2],"samsung");
  76.  
  77. srand(Word);
  78. pick = rand()%2;
  79.  
  80. system("COLOR F");
  81.  
  82. for (i=0;i<strlen(Word);i++)
  83. {
  84. guessed[i]='_';
  85.  
  86. if(Word[pick][i]==' ')
  87. {
  88. guessed[i]=' ';
  89. }
  90. }
  91.  
  92. while (attempt<=6||strcmp(Word,guessed)==0)
  93. {
  94. system("cls");
  95. displayscreen();
  96.  
  97. {
  98. printf("\n\tGuessing Word:");
  99. }
  100.  
  101. for(i=0;i<strlen(Word);i++)
  102. {
  103. printf(" %c ",guessed[i]);
  104. }
  105.  
  106. if (strcmp(Word,guessed)==0)
  107. {
  108. printf("\n\tYou Have Guessed The Correct Word!");
  109. system("mario_win.wav");
  110. }
  111. else if (attempt==6)
  112. {
  113. printf("\n\tYou Lose!");
  114. system("mario_lose.wav");
  115. }
  116.  
  117. hangman(attempt);
  118. letter=getche();
  119.  
  120. for (i=0; i<strlen(Word);i++)
  121. {
  122. if (Word[i]==letter)
  123. {
  124. guessed[i]=letter;
  125. }
  126. else
  127. {
  128. attempt++;
  129. }
  130. }
  131.  
  132. if (attempt==6||strcmp(Word,guessed)==0)
  133. {
  134. break;
  135. }
  136.  
  137. }
  138. puts("\nPress any key to start, 'q' - to quit");
  139. key=getch();
  140. while (key!= 113 )
  141. {
  142. return answer;
  143. }
  144. }
  145.  
  146. void hangman(int attempt)
  147. {
  148. puts("\n");
  149. puts("\t ############");
  150. puts("\t ### ##");
  151. puts("\t ### ##");
  152.  
  153. if (attempt<=0)
  154. {
  155. puts("\t ###");
  156. puts("\t ###");
  157. puts("\t ###");
  158. puts("\t ###");
  159. }
  160. else
  161. {
  162. printf("\t ###");
  163. //system("COLOR 5");
  164. puts(" +-----+");
  165. //system("COLOR 1");
  166. printf("\t ###");
  167. //system("COLOR 5");
  168. puts(" | |");
  169. //system("COLOR 1");
  170. printf("\t ###");
  171. //system("COLOR 5");
  172. puts(" | |");
  173. //system("COLOR 1");
  174. printf("\t ###");
  175. //system("COLOR 5");
  176. puts(" +-----+");
  177. //system("COLOR 1");
  178. }
  179.  
  180. if (attempt==2)
  181. {
  182. printf("\t ###");
  183. //system("COLOR 5");
  184. puts(" ||");
  185. //system("COLOR 1");
  186. printf("\t ###");
  187. //system("COLOR 5");
  188. puts(" ||");
  189. //system("COLOR 1");
  190. printf("\t ###");
  191. //system("COLOR 5");
  192. puts(" ||");
  193. //system("COLOR 1");
  194. }
  195. else if (attempt==3)
  196. {
  197. printf("\t ###");
  198. //system("COLOR 5");
  199. puts(" ||");
  200. //system("COLOR 1");
  201. printf("\t ###");
  202. //system("COLOR 5");
  203. puts(" ====||");
  204. //system("COLOR 1");
  205. printf("\t ###");
  206. //system("COLOR 5");
  207. puts(" ||");
  208. //system("COLOR 1");
  209. }
  210. else if ( attempt <= 3 )
  211. {
  212. puts("\t ###");
  213. puts("\t ###");
  214. puts("\t ###");
  215. }
  216. else
  217. {
  218. printf("\t ###");
  219. //system("COLOR 5");
  220. puts(" ||\t");
  221. //system("COLOR 1");
  222. printf("\t ###");
  223. //system("COLOR 5");
  224. puts(" ====||====");
  225. //system("COLOR 1");
  226. printf("\t ###");
  227. //system("COLOR 5");
  228. puts(" ||\t");
  229. //system("COLOR 1");
  230. }
  231. if (attempt==5)
  232. {
  233. printf("\t ###");
  234. //system("COLOR 5");
  235. puts(" //");
  236. //system("COLOR 1");
  237. printf("\t ###");
  238. //system("COLOR 5");
  239. puts(" // ");
  240. //system("COLOR 1");
  241. }
  242. else if (attempt<=5)
  243. {
  244. puts("\t ###");
  245. puts("\t ###");
  246. }
  247. else
  248. {
  249. printf("\t ###");
  250. //system("COLOR 5");
  251. puts(" //\\\\ ");
  252. //system("COLOR 1");
  253. printf("\t ###");
  254. //system("COLOR 5");
  255. puts(" // \\\\");
  256. //system("COLOR 1");
  257. }
  258. puts("\t ###");
  259. puts("\t#######");
  260. puts("\t#######");
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement