Guest User

Untitled

a guest
Jun 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <ctime>
  4. #include <conio.h>
  5. using namespace std;
  6.  
  7. int Gameslost; int Gameswon;
  8.  
  9. void PlaceCursor(const int x, const int y) {
  10.  
  11. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  12.  
  13. COORD PlaceCursorHere;
  14. PlaceCursorHere.X = x;
  15. PlaceCursorHere.Y = y;
  16.  
  17. SetConsoleCursorPosition(hConsole, PlaceCursorHere);
  18. return;
  19. }
  20.  
  21. void MissedLetter(int miss) {
  22.  
  23. switch (miss) {
  24. case 1: PlaceCursor(55, 4); cout << ("0"); break;
  25. case 2: PlaceCursor(55, 5); cout << ("|"); break;
  26. case 3: PlaceCursor(54, 5); cout << ("/"); PlaceCursor(56, 5); cout << ("\\"); break;
  27. case 4: PlaceCursor(54, 6); cout << ("/"); PlaceCursor(56, 6); cout << ("\\"); break;
  28. case 5: Gameslost++; PlaceCursor(50, 8); cout << ("Game over!!!"); break;
  29. }
  30.  
  31. return;
  32. }
  33.  
  34. void ClearConsole() {
  35.  
  36. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  37.  
  38. COORD coordScreen = { 0, 0 };
  39. DWORD cCharsWritten;
  40. CONSOLE_SCREEN_BUFFER_INFO csbi;
  41. DWORD dwConSize;
  42.  
  43. if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }
  44. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  45.  
  46. if (!FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten)) { return; }
  47. if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) { return; }
  48. if (!FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten)) { return; }
  49.  
  50. return;
  51. }
  52.  
  53. void Help() {
  54. PlaceCursor(0, 10);
  55. cout << ("The computer stores a word and the player tries to guess it by suggesting letters.\n") << ("If the suggested letter does not occur in the word, the computer draws one element of the hangman.\n");
  56. cout << ("The game is over when: \n") << (" The guessing player completes the word.\n") << (" The computer completes the hangman diagram.\n") << ("\n") << ("Press any key to continue!");
  57. getch();
  58. ClearConsole();
  59. return;
  60. }
  61.  
  62. void Score(int Gameswon, int Gameslost) {
  63. PlaceCursor(0, 15);
  64. cout << ("Games won: ") << Gameswon << "\n" << ("Games lost: ") << Gameslost << "\n" << "\n" << ("Press any key to continue!");
  65. getch();
  66. ClearConsole();
  67. return;
  68. }
  69.  
  70. int main() {
  71.  
  72. Gameslost = Gameswon = 0;
  73. bool Game = true;
  74.  
  75. char *WordLibrary[] = {
  76. "automobile",
  77. "baker",
  78. "carrot",
  79. "darkness",
  80. "ellipse",
  81. "forest",
  82. "garrison",
  83. "house",
  84. "integral",
  85. "jumper",
  86. "kangaroo",
  87. "lamp",
  88. "monocle",
  89. "night",
  90. "owl",
  91. "peanut",
  92. "quintuple",
  93. "rebus",
  94. "soft",
  95. "teapot",
  96. "umbrella",
  97. "velocity",
  98. "water",
  99. "xerox",
  100. "yacht",
  101. "zebra"
  102.  
  103. };
  104.  
  105. while(Game == true) {
  106.  
  107. ClearConsole();
  108. srand((unsigned)time(0));
  109. int Selected = rand() % 26;
  110. int miss = 0;
  111. char *Word = WordLibrary[Selected];
  112. int WordLength = strlen(WordLibrary[Selected]);
  113. char guess;
  114. int Completion = WordLength;
  115. bool GotOne = false;
  116. bool Uncomplete;
  117. int mov = 0;
  118.  
  119. PlaceCursor(0, 0);
  120. cout << ("|| || /\\ |\\\\ || /--| /\\ /\\ /\\ |\\\\ ||") << "\n";
  121. cout << ("||--|| //\\\\ ||\\\\||| --| //\\\\//\\\\ //\\\\ ||\\\\||") << "\n";
  122. cout << ("||--|| //==\\\\ || \\ || |__/| // \\/ \\\\ //==\\\\ || \\ |") << "\n";
  123. cout << ("|| ||// \\\\|| \\| \\____/// \\\\// \\\\|| \\|") << "\n";
  124.  
  125. PlaceCursor(0, 5);
  126. cout << ("[1] Go!\n") << ("[2] Help.\n") << ("[3] Scoreboard.\n") << ("[4] Exit.\n");
  127. cout << ("Menu: ");
  128. int Menu_choice;
  129. cin >> Menu_choice;
  130.  
  131. switch (Menu_choice) {
  132. case 1: ClearConsole(); break;
  133. case 2: Help(); break;
  134. case 3: Score(Gameswon, Gameslost); break;
  135. case 4: Game = false; break;
  136. }
  137.  
  138. if(Menu_choice == 1) {
  139. PlaceCursor(0, 2);
  140. cout << ("Word: ");
  141. PlaceCursor(0, 3);
  142. cout << ("False letters used: ");
  143.  
  144. PlaceCursor(45, 2); cout << (" _______");
  145. PlaceCursor(45, 3); cout << (" | |");
  146. PlaceCursor(45, 4); cout << (" |");
  147. PlaceCursor(45, 5); cout << (" |");
  148. PlaceCursor(45, 6); cout << (" |");
  149. PlaceCursor(45, 7); cout << ("__|__");
  150.  
  151. for (int x = 0; x < WordLength; x++) {
  152. PlaceCursor(x + 6, 2); cout << ("_"); }
  153. Uncomplete = true;
  154.  
  155. while (Uncomplete == true) {
  156. PlaceCursor(0, 1);
  157. cout << ("Your guess: ");
  158. cin >> guess;
  159.  
  160.  
  161. for (int x = 0; x <= WordLength; x++) {
  162.  
  163. if (guess == Word[x]) {
  164. PlaceCursor(x + 6, 2);
  165. cout << Word[x];
  166. --Completion;
  167. GotOne = true;
  168. }
  169. }
  170.  
  171. if (GotOne == false) {
  172. PlaceCursor(20+mov, 3);
  173. cout << guess << (",");
  174. mov += 3;
  175. miss++;
  176. if (miss == 5) {
  177. Uncomplete = false;
  178. }
  179. MissedLetter(miss);
  180. }
  181. else {
  182. GotOne = false;
  183. }
  184.  
  185. if (Completion == 0) { mov = 0; Uncomplete = false; PlaceCursor(0, 8); Gameswon++; }
  186. }
  187.  
  188.  
  189. miss = 0;
  190.  
  191. ClearConsole();
  192. }
  193. }
  194. return 0;
  195. }
Add Comment
Please, Sign In to add comment