Advertisement
Guest User

Untitled

a guest
May 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h> //random
  4. #include <string.h> // char commands
  5. #include <windows.h> //for colors [works only on windows]
  6.  
  7. #define LIVES 11
  8. //functionnal wihtout the feature to check letters that have been guessed.
  9. //remove comment at line 90 to add feature but break when mistakes are done.
  10. //normal difficulty does not work because it doesn't attribute the last few characters when the word is from 5 to 10 characters
  11.  
  12. // prototypes
  13. void play(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
  14. void generate(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
  15. void difficulty(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount);
  16. //
  17.  
  18. void play(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
  19. {
  20. chainlength = strlen(word); //takes value of length of word
  21. char wordend[chainlength];
  22. fchoice = 3;
  23. char wordtemp[15] = "_______________";
  24. for(i = 0; i <= chainlength; i++)
  25. {
  26. wordend[i] = wordtemp[i];
  27. }
  28.  
  29. char *check = word;
  30. char *checkend = wordend;
  31. char *letterguessed = wordend;
  32. unsigned int checkcounter = 0;
  33. system("PAUSE");
  34. system("cls");
  35.  
  36. while(strcmp(word,wordend) != 0) //compares word with word end and returns 0 if they're equal
  37. {
  38. loop:
  39. if(life < 1)
  40. {
  41. if(wincount > 0)
  42. wincount = 0;
  43. if(wincount <= 0)
  44. wincount = wincount-1;
  45. color = 14;
  46. SetConsoleTextAttribute(hConsole, color);
  47. printf("\n\n\t\t\t\t\tWin count: ");
  48. color = 12;
  49. SetConsoleTextAttribute(hConsole, color);
  50. printf("%d\n", wincount);
  51. color = 15;
  52. SetConsoleTextAttribute(hConsole, color);
  53. do{
  54. printf("\n\t\t\tYou lost.\n\n\tThe word was %s.\n\n\tBetter luck next time!\n\n", word);
  55. system("PAUSE");
  56. printf("Would you like to play again?\n\n1 - Yes\n\n 2 - No");
  57. scanf("%d",&fchoice);
  58. }while(fchoice < 1 || fchoice > 2);
  59. if(fchoice == 1)
  60. difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
  61. if(fchoice == 2)
  62. exit(0);
  63.  
  64. }
  65. color = 14;
  66. SetConsoleTextAttribute(hConsole, color);
  67. printf("\t\tCurrent lives left: ");
  68. color = 12;
  69. SetConsoleTextAttribute(hConsole, color);
  70. printf("%d\n", life);
  71. color = 14;
  72. SetConsoleTextAttribute(hConsole, color);
  73. printf("\n\n\t\t\t\t\tWin count: ");
  74. color = 12;
  75. SetConsoleTextAttribute(hConsole, color);
  76. printf("%d\n", wincount);
  77. color = 14;
  78. SetConsoleTextAttribute(hConsole, color);
  79. printf("\n\nInput \" . \"to see previous letters that were decided.\t [COSTS A LIFE]\n\n");
  80. color = 15;
  81. SetConsoleTextAttribute(hConsole, color);
  82. printf(" %s\t", wordend);
  83. //printf("The word is %s\n\n", word);
  84. printf("\nGuess a letter.\n\n");
  85. scanf(" %c", &*letter);
  86. if(*letter == '.')
  87. {
  88. checkcounter++;
  89. life--;
  90. printf("Letters guessed:");
  91. for(i = LIVES; i > life+checkcounter; i--)
  92. {
  93. printf(" %c ", letterguessed[i]);
  94. }
  95. printf("\n\n\n");
  96. system("PAUSE");
  97. system("cls");
  98. goto loop;
  99. }
  100. check = word;
  101. for(i = 0; i < chainlength; i++)
  102. {
  103. if(strchr(check, *letter))
  104. {
  105. //printf(" %c at position %d", *letter, i+1);
  106. if(word[i] == *letter)
  107. {
  108. printf(" _%c_\t", *letter);
  109. wordend[i] = *letter;
  110. }
  111. }
  112. if(word[i] != *letter)
  113. printf("__\t");
  114. }
  115. if(!strchr(check, *letter))
  116. {
  117. //letterguessed[life] = *letter; //LINE THAT BREAKS HARD DIFFICTULY BUT MAKES THE REMIND CHECK WORK
  118. life--;
  119. }
  120. printf("\n\n");
  121. system("PAUSE");
  122. system("cls");
  123. }
  124.  
  125. if(wincount > 0)
  126. wincount = wincount+1;
  127. if(wincount <= 0)
  128. wincount = 1;
  129. color = 14;
  130. SetConsoleTextAttribute(hConsole, color);
  131. printf("\n\n\t\t\t\t\tWin count: ");
  132. color = 12;
  133. SetConsoleTextAttribute(hConsole, color);
  134. printf("%d\n", wincount);
  135. color = 15;
  136. SetConsoleTextAttribute(hConsole, color);
  137. do{
  138. printf("Congratulation! You have found the word.\n\nWould you like to play again?\n\n1 - Yes\n\n 2 - No");
  139. system("PAUSE");
  140. scanf("%d",&fchoice);
  141. }while(fchoice < 1 || fchoice > 2);
  142. if(fchoice == 1)
  143. difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
  144. if(fchoice == 2)
  145. exit(0);
  146. //printf("The word is %s\n\n", word);1
  147. system("PAUSE");
  148. }
  149.  
  150. void generate(char *word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
  151. {
  152. random = rand()%9;
  153. if (fchoice == 1)
  154. strcpy(word, easy[random]);
  155. if (fchoice == 2)
  156. strcpy(word, normal[random]);
  157. if (fchoice == 3)
  158. strcpy(word, hard[random]);
  159. play(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
  160. }
  161.  
  162. void difficulty(char* word, char** easy, char** normal, char** hard, unsigned int fchoice, unsigned int i, unsigned int random, unsigned int chainlength, char* letter, unsigned int life, int color, void *hConsole, int wincount)
  163. {
  164. life = LIVES;
  165. do{
  166. printf("Select the difficulty.\n1 = Easy\n2 = Normal\n3 = Hard\n\n");
  167. scanf("%d", &fchoice);
  168. if(fchoice < 1 || fchoice > 3)
  169. {
  170. printf("%d is not a valid choice. Please select a number beetween 1 and 3.\n", fchoice);
  171. }
  172. }while(fchoice < 1 || fchoice > 3);
  173. generate(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
  174.  
  175. }
  176.  
  177. int main()
  178. {
  179. srand(time(NULL));
  180. char word[15];
  181. unsigned int chainlength = 0;
  182. unsigned int life = LIVES;
  183. char* easy[9];
  184. easy[0] = "dog";
  185. easy[1] = "cat";
  186. easy[2] = "pat";
  187. easy[3] = "eye";
  188. easy[4] = "pie";
  189. easy[5] = "tie";
  190. easy[6] = "sigh";
  191. easy[7] = "cry";
  192. easy[8] = "love";
  193. easy[9] = "chick";
  194. char* normal[9];
  195. normal[0] = "figure";
  196. normal[1] = "window";
  197. normal[2] = "shadow";
  198. normal[3] = "output";
  199. normal[4] = "rewinding";
  200. normal[5] = "sorrow";
  201. normal[6] = "capture";
  202. normal[7] = "adventure";
  203. normal[8] = "magician";
  204. normal[9] = "earlier";
  205. char* hard[9];
  206. hard[0] = "unrelatable"; //glitches
  207. hard[1] = "constitution"; //glitches
  208. hard[2] = "scientifique"; //glitches
  209. hard[3] = "unbelievable";// glitches
  210. hard[5] = "microbiology";
  211. hard[4] = "optimizable";
  212. hard[6] = "irresponsible";
  213. hard[7] = "unstoppable";
  214. hard[8] = "fundementally";
  215. hard[9] = "loathfull";
  216. unsigned int fchoice = 0;
  217. unsigned int random = 0;
  218. unsigned int i = 0;
  219. HANDLE hConsole;
  220. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  221. int color = 0;
  222. char letter[] = "a";
  223. int wincount = 0;
  224. difficulty(word, easy, normal, hard, fchoice, i, random, chainlength, letter, life, color, hConsole, wincount/*, Varirables*/);
  225. fflush(stdin); // option ONE to clean stdin
  226. return 0;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement