Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include "character.h"
  6. #include "enemy.h"
  7. #include "game.h"
  8.  
  9. using namespace std;
  10.  
  11. // Change Color
  12. int *switchColor(int choice, int *array) {
  13. switch (choice) {
  14. case 1:
  15. array[0] = RED;
  16. array[1] = GREEN;
  17. array[2] = GREEN;
  18. array[3] = GREEN;
  19. array[4] = GREEN;
  20. break;
  21. case 2:
  22. array[0] = GREEN;
  23. array[1] = RED;
  24. array[2] = GREEN;
  25. array[3] = GREEN;
  26. array[4] = GREEN;
  27. break;
  28. case 3:
  29. array[0] = GREEN;
  30. array[1] = GREEN;
  31. array[2] = RED;
  32. array[3] = GREEN;
  33. array[4] = GREEN;
  34. break;
  35. case 4:
  36. array[0] = GREEN;
  37. array[1] = GREEN;
  38. array[2] = GREEN;
  39. array[3] = RED;
  40. array[4] = GREEN;
  41. break;
  42. case 5:
  43. array[0] = GREEN;
  44. array[1] = GREEN;
  45. array[2] = GREEN;
  46. array[3] = GREEN;
  47. array[4] = RED;
  48. break;
  49. }
  50. return array;
  51. }
  52. // Hide Cursor
  53. void ShowConsoleCursor(bool showFlag)
  54. {
  55. HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
  56.  
  57. CONSOLE_CURSOR_INFO cursorInfo;
  58.  
  59. GetConsoleCursorInfo(out, &cursorInfo);
  60. cursorInfo.bVisible = showFlag; // set the cursor visibility
  61. SetConsoleCursorInfo(out, &cursorInfo);
  62. }
  63.  
  64. // Duel
  65. int Duel(Character *mainCharacter, Character *mob, HANDLE *hConsole) {
  66.  
  67. SetConsoleTextAttribute(*hConsole, GREEN);
  68. cout << "Napotykasz ";
  69. SetConsoleTextAttribute(*hConsole, RED);
  70. cout << mob->name;
  71. SetConsoleTextAttribute(*hConsole, GREEN);
  72. cout << "poziomu: ";
  73. SetConsoleTextAttribute(*hConsole, RED);
  74. cout << mob->level;
  75. SetConsoleTextAttribute(*hConsole, GREEN);
  76. cout << "!" << endl;
  77.  
  78. while (mainCharacter->alive == true && mob->alive == true) {
  79. if (mainCharacter->level >= mob->level) {
  80. mainCharacter->attack(mob);
  81. }
  82. mob->attack(mainCharacter);
  83. }
  84. if (mainCharacter->alive == false) {
  85. mainCharacter->~Character;
  86. cout << "Niestety przegrywasz ten pojedynek!" << endl;
  87. SetConsoleTextAttribute(*hConsole, RED);
  88. cout << "Koniec Gry!" << endl;
  89. return 1;
  90. }
  91. else if (mob->alive == false) {
  92. SetConsoleTextAttribute(*hConsole, GREEN);
  93. cout << "Pokonujesz " << mob->name << "!" << endl;
  94.  
  95. if (mob->equipment.size > 1) {
  96. cout << "Otrzymujesz: ";
  97. cout << mob->equipment[1]->name;
  98. mainCharacter->stash(mob->equipment[1]);
  99. }
  100. //mob->~Character;
  101. }
  102. return 0;
  103. }
  104.  
  105. // Game
  106. int Game(bool *loop, int *choice, int *col, HANDLE *hConsole, string *name, Character *mainCharacter) {
  107.  
  108. char c;
  109. Item *current;
  110. int amount;
  111. bool choosed = false;
  112. unsigned floor = 1;
  113. *loop = true;
  114. *choice = 1;
  115.  
  116. while (*loop == true) {
  117.  
  118. system("CLS");
  119. switchColor(*choice, col);
  120.  
  121. SetConsoleTextAttribute(*hConsole, GREEN);
  122. cout << "===============" << endl;
  123. SetConsoleTextAttribute(*hConsole, RED);
  124. cout << "Pietro: " << floor << endl;
  125. SetConsoleTextAttribute(*hConsole, GREEN);
  126. cout << "===============" << endl;
  127. SetConsoleTextAttribute(*hConsole, col[0]);
  128. cout << "Idz na przod" << endl;
  129. SetConsoleTextAttribute(*hConsole, col[1]);
  130. cout << "Ekwipunek" << endl;
  131. SetConsoleTextAttribute(*hConsole, col[2]);
  132. cout << "Techniki" << endl;
  133. SetConsoleTextAttribute(*hConsole, col[3]);
  134. cout << "Sklep" << endl;
  135. SetConsoleTextAttribute(*hConsole, col[4]);
  136. cout << "Zapisz i wyjdz z gry" << endl;
  137. SetConsoleTextAttribute(*hConsole, GREEN);
  138.  
  139. switch ((c = _getch())) {
  140. case KEY_DOWN:
  141. if (*choice != 5) {
  142. *choice += 1;
  143. }
  144. break;
  145. case KEY_UP:
  146. if (*choice != 1) {
  147. *choice -= 1;
  148. }
  149. break;
  150. case KEY_ENTER:
  151. choosed = true;
  152. break;
  153. }
  154. if (choosed == true) {
  155. switch (*choice) {
  156. case 1:
  157. // Wygeneruj moba, sekwencja walki, zwolnij miejsce po ubiciu moba lub wyswietl koniec gry przy dedzie
  158. if (floor < 5) {
  159. Zombie mob;
  160. if (Duel(mainCharacter, &mob, hConsole) == 1) {
  161. *loop = false;
  162. }
  163. }
  164. break;
  165. case 2:
  166. // Wyswietl ekwipunek
  167. system("CLS");
  168. amount = mainCharacter->equipment.size();
  169. cout << "Liczba przedmiotow w ekwipunku: " << amount << endl;
  170.  
  171. for (int i = 1; i <= amount; i++) {
  172. current = mainCharacter->equipment[i-1];
  173. cout << "================" << endl;
  174. if (current->legendary == true) {
  175. SetConsoleTextAttribute(*hConsole, GOLD);
  176. }
  177. else {
  178. SetConsoleTextAttribute(*hConsole, RED);
  179. }
  180. cout << current->name << endl;
  181. SetConsoleTextAttribute(*hConsole, GREEN);
  182. cout << current->desc << endl;
  183. SetConsoleTextAttribute(*hConsole, AQUA);
  184. cout << "Atak: " << current->attc << endl;
  185. cout << "Zdrowie: " << current->health << endl;
  186. cout << "Mana: " << current->mana << endl;
  187. cout << "Szczescie: " << current->luck << endl;
  188. cout << "Obureczny: ";
  189. if (current->twoHanded == true) {
  190. cout << "tak" << endl;
  191. }
  192. else {
  193. cout << "nie" << endl;
  194. }
  195. SetConsoleTextAttribute(*hConsole, GREEN);
  196. cout << "================" << endl;
  197. }
  198. cout << "Wcisnij ENTER aby wrocic" << endl;
  199. while (1) {
  200.  
  201. if ((c = _getch()) == KEY_ENTER) {
  202. choosed = false;
  203. break;
  204. }
  205. }
  206. break;
  207. case 3:
  208. // Techniki
  209. break;
  210. case 4:
  211. // SKlep
  212. break;
  213. case 5:
  214. // Zapisz i wyjdz
  215. *loop = false;
  216. exit(1);
  217. break;
  218. }
  219. }
  220. }
  221.  
  222. return 0;
  223. }
  224. // New Game
  225. int newGame() {
  226. string name;
  227. HANDLE hConsole;
  228. int choice = 1, col[5];
  229. char c;
  230. bool loop = true;
  231.  
  232. ShowConsoleCursor(false);
  233. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  234.  
  235. // Class choice menu loop
  236. while(loop == true) {
  237. system("CLS");
  238. switchColor(choice,col);
  239. SetConsoleTextAttribute(hConsole, GREEN);
  240. cout << ":::::Wybierz swoja klase:::::" << endl;
  241. cout << "=============================" << endl;
  242. SetConsoleTextAttribute(hConsole, col[0]);
  243. cout << "Barbarzynca ";
  244. SetConsoleTextAttribute(hConsole, col[1]);
  245. cout << " Mag" << endl;
  246. SetConsoleTextAttribute(hConsole, GREEN);
  247.  
  248. switch((c = _getch())) {
  249. case KEY_RIGHT:
  250. if (choice != 2) {
  251. choice++;
  252. }
  253. break;
  254. case KEY_LEFT:
  255. if (choice != 1) {
  256. choice--;
  257. }
  258. break;
  259. case KEY_ENTER:
  260. loop = false;
  261. break;
  262. }
  263. }
  264. // Character name
  265. system("CLS");
  266. cout << "===========================" << endl;
  267. cout << "Nadaj nazwe swojej postaci!" << endl;
  268. cout << "===========================" << endl;
  269. ShowConsoleCursor(true);
  270. SetConsoleTextAttribute(hConsole, RED);
  271. cin >> name;
  272. SetConsoleTextAttribute(hConsole, GREEN);
  273. system("CLS");
  274.  
  275. cout << "Startuje..." << endl;
  276. // Barbarian
  277. if (choice == 1) {
  278. Barbarian mainCharacter;
  279. mainCharacter.name = name;
  280. Game(&loop, &choice, col, &hConsole, &name, &mainCharacter);
  281. }
  282. // Mage
  283. if (choice == 2) {
  284. Mage mainCharacter;
  285. mainCharacter.name = name;
  286. Game(&loop, &choice, col, &hConsole, &name, &mainCharacter);
  287. }
  288. return 0;
  289. }
  290.  
  291. // Main Menu
  292. int main_menu() {
  293. HANDLE hConsole;
  294. int col[3];
  295. int choice = 1;
  296. int input;
  297.  
  298. ShowConsoleCursor(false);
  299. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  300. while (1) {
  301. switchColor(choice,col);
  302. SetConsoleTextAttribute(hConsole, GREEN);
  303. system("CLS");
  304. cout << ".....:::::<Insert_title> The Game:::::....." << endl;
  305. cout << "===========================================" << endl;
  306. SetConsoleTextAttribute(hConsole, col[0]);
  307. cout << "Nowa Gra" << endl;
  308. SetConsoleTextAttribute(hConsole, col[1]);
  309. cout << "Wczytaj ostatni zapis" << endl;
  310. SetConsoleTextAttribute(hConsole, col[2]);
  311. cout << "Wyjdz z gry" << endl;
  312. SetConsoleTextAttribute(hConsole, GREEN);
  313. switch((input = _getch())) {
  314. case KEY_DOWN:
  315. //cout << "KEY_DOWN" << endl;
  316. if (choice != 3) {
  317. choice++;
  318. }
  319. break;
  320. case KEY_UP:
  321. //cout << "KEY_UP" << endl;
  322. if (choice != 1) {
  323. choice--;
  324. }
  325. break;
  326. case KEY_ENTER:
  327. switch (choice) {
  328. case 1:
  329. newGame();
  330. break;
  331. case 2:
  332. //loadGame();
  333. break;
  334. case 3:
  335. exit(1);
  336. break;
  337. }
  338. }
  339. }
  340. return 0;
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement