Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. int enemyHP = 100;
  13. int yourHP = 100;
  14. int enemyNRG = 40; //NRG stands for energy
  15. int yourNRG = 40;
  16. srand(time(NULL));
  17. int normalDMG = rand() % 9 + 1;
  18. int specialDMG = rand() % 15 + 5;
  19. int enemyrandomattack = rand() % 4 + 1; // random enemy action
  20. int input, n = 0;
  21. int enemyDodge = 0;
  22. int yourDodge = 0;
  23. int action;
  24. int runenemyattack = 1;
  25.  
  26. enum actions
  27. {
  28. Attack = 1,
  29. SpecialAttack = 2,
  30. Heal = 3,
  31. Dodge = 4,
  32. Recharge = 5,
  33. };
  34.  
  35. cout << "Welcome!" << endl;
  36. cout << "Press 1 for a normal attack (80% chance of hitting 1 - 10)" << endl;
  37. cout << "Press 2 for a special attack (50% chance of hitting 5 - 20)" << endl;
  38. cout << "Press 3 to use half of you current energy to heal for that amount" << endl;
  39. cout << "Press 4 to decrease the chance of the enemy hitting you by 30% next turn (decreases your energy regeneration by 50% this turn)" << endl;
  40. cout << "Press 5 to recharge your energy 4 times the rate but the enemy has a 10% higher chance of hitting you this turn" << endl << endl << endl;
  41. do {
  42. int HEALING = 0; // Lets the player to heal first and not use up the turn
  43. do
  44. {
  45. input = _getch() - '0';
  46.  
  47. switch (input)
  48. {
  49. case Attack:
  50. if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss
  51. {
  52. if (yourNRG < 40)
  53. {
  54. yourNRG = (yourNRG + 10);
  55. if (yourNRG > 40)
  56. {
  57. yourNRG = 40;
  58. }
  59. }
  60. action = rand() % 9 + 1;
  61. if (action > 2) // the player has an 80% chance of hitting
  62. {
  63. normalDMG = rand() % 9 + 1;
  64. enemyHP -= normalDMG;
  65. cout << "You used a normal attack and did " << normalDMG << " damage!" << endl;
  66. HEALING = 2;
  67. break;
  68. }
  69. else
  70. {
  71. cout << "The player tried using a normal attack but missed!" << endl;
  72. HEALING = 2;
  73. break;
  74. }
  75. }
  76. if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing
  77. {
  78. if (yourNRG < 40)
  79. {
  80. yourNRG = (yourNRG + 10);
  81. if (yourNRG > 40)
  82. {
  83. yourNRG = 40;
  84. }
  85. enemyDodge = 0; // uses up the enemy's dodge
  86. action = rand() % 9 + 1;
  87. if (action > 5) // 50% chance of the player hitting a normal attack due to the enemy dodging
  88. {
  89. normalDMG = rand() % 9 + 1;
  90. enemyHP -= normalDMG;
  91. cout << "You used normal attack and did " << normalDMG << " damage!" << endl;
  92. HEALING = 2;
  93. break;
  94. }
  95. else
  96. {
  97. cout << "The player tried using a normal attack but missed!" << endl;
  98. HEALING = 2;
  99. break;
  100. }
  101. }
  102. break;
  103. }
  104.  
  105. case SpecialAttack:
  106. if (yourNRG < 40)
  107. {
  108. cout << "You do not have enough energy to use a special attack!" << endl;
  109. HEALING = 0;
  110. break;
  111. }
  112. if (yourNRG == 40)
  113. {
  114. if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss
  115. {
  116. if (rand() % 9 + 1 > 5) // the player has a 50% chance of hitting
  117. {
  118. enemyHP -= specialDMG;
  119. cout << "You used a special attack and did " << specialDMG << " damage!" << endl;
  120. yourNRG = 10; // uses up 40 energy and then adds 10 at the end of the turn (saves lines of code) (40-40+10)
  121. HEALING = 2;
  122. break;
  123. }
  124. else
  125. {
  126. cout << "The player tried using a special attack but missed!" << endl;
  127. yourNRG = 10;
  128. HEALING = 2;
  129. break;
  130. }
  131. }
  132. if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing
  133. {
  134. enemyDodge = 0; // uses up the enemy's dodge
  135. if (rand() % 9 + 1 > 8) // 20% chance of the player hitting a special attack due to the enemy dodging
  136. {
  137. enemyHP -= specialDMG;
  138. cout << "You used a special attack and did " << specialDMG << " damage!" << endl;
  139. yourNRG = 10;
  140. HEALING = 2;
  141. break;
  142. }
  143. else
  144. {
  145. cout << "The player tried using a special attack but missed!" << endl;
  146. yourNRG = 10;
  147. HEALING = 2;
  148. break;
  149. }
  150. }
  151. }
  152.  
  153. case Heal:
  154. if (HEALING == 0) // only lets the player heal as his first action and not use up the turn
  155. {
  156. yourHP += (yourNRG / 2);
  157. if (yourHP >= 100)
  158. {
  159. yourHP = 100;
  160. }
  161. cout << "Your creature healed itself and now has " << yourHP << " HP" << endl;
  162. HEALING++; //stops the player from healing twice in one turn, because HEALING will no longer be == 0
  163. break;
  164. }
  165. case Dodge:
  166. yourDodge = 1;
  167. if (yourNRG < 40)
  168. {
  169. yourNRG = (yourNRG + 5); // gains 5 instead of 10 because the energy gained per turn is halved by using dodge that turn
  170. if (yourNRG > 40)
  171. {
  172. yourNRG = 40; // does not let the player's energy exceed 40
  173. }
  174. }
  175. cout << "Your creature gets ready to evade the enemy" << endl;
  176. HEALING = 2;
  177. break;
  178.  
  179. case Recharge:
  180. yourNRG = 40;
  181. cout << "Your creature recharged it's energy" << endl;
  182. HEALING = 2;
  183. break;
  184.  
  185. default:
  186. cout << "Unknown action try 1-5" << endl;
  187. HEALING = 1;
  188. break;
  189. }
  190.  
  191. } while (HEALING != 2); // The player's turn ends once he uses an action other than heal
  192.  
  193. // The lines below are the enemy's actions
  194.  
  195. enemyrandomattack = rand() % 4 + 1; // generates a random enemy action
  196. if (runenemyattack = 1)
  197. {
  198.  
  199. if (enemyrandomattack == 1) // if the number one is randomly generated the enemy then does a normal attack
  200. {
  201. if (enemyNRG < 40)
  202. {
  203. enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
  204. if (enemyNRG > 40)
  205. {
  206. enemyNRG = 40; //does not let the enemy exceed 40 energy
  207. }
  208. }
  209. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
  210. {
  211. action = rand() % 9 + 1;
  212. if (action > 2) // the enemy has an 80% chance of hitting
  213. {
  214. normalDMG = rand() % 9 + 1;
  215. yourHP -= normalDMG;
  216. cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
  217. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  218.  
  219. }
  220. else
  221. {
  222. cout << "The enemy tried using a normal attack but missed!" << endl;
  223. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  224.  
  225. }
  226. }
  227. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  228. {
  229. yourDodge = 0; // uses up players dodge
  230. action = rand() % 9 + 1;
  231. if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
  232. {
  233. normalDMG = rand() % 9 + 1;
  234. yourHP -= normalDMG;
  235. cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
  236. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  237.  
  238. }
  239. else
  240. {
  241. cout << "The enemy tried using a normal attack but missed!" << endl;
  242. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  243.  
  244. }
  245. }
  246. }
  247. if (enemyrandomattack == 2 && enemyNRG < 40) // if a special attack action is generated and the enemy does not have max energy the enemy will then recharge instead
  248. {
  249. enemyNRG = 40;
  250. cout << "The enemy decided to rest for a turn and fully regenerated it's energy" << endl;
  251. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  252.  
  253. }
  254. if (enemyrandomattack == 2 && enemyNRG == 40) // enemy special attack
  255. {
  256. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss
  257. {
  258. if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting
  259. {
  260. yourHP -= specialDMG;
  261. cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
  262. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  263. enemyNRG = 10; // energy gained at the end of the turn
  264.  
  265. }
  266. else
  267. {
  268. enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10)
  269. cout << "The enemy tried using a special attack but missed!" << endl;
  270. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  271.  
  272. }
  273. }
  274. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  275. {
  276. yourDodge = 0; // uses up players dodge
  277. if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging
  278. {
  279. yourHP -= specialDMG;
  280. cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
  281. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  282. enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code
  283.  
  284. }
  285. else
  286. {
  287. cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl;
  288. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  289.  
  290. }
  291. }
  292. }
  293.  
  294. if (enemyrandomattack == 3 && enemyHP == 100) // if the enemy already had max hp and rolled the heal action he will then attack instead
  295. {
  296. if (enemyNRG < 40)
  297. {
  298. enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
  299. if (enemyNRG > 40)
  300. {
  301. enemyNRG = 40; //does not let the enemy exceed 40 energy
  302. }
  303. }
  304. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
  305. {
  306. if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting
  307. {
  308. yourHP -= normalDMG;
  309. cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
  310. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  311.  
  312. }
  313. else
  314. {
  315. cout << "The enemy tried using a normal attack but missed!" << endl;
  316. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  317.  
  318. }
  319. }
  320. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  321. {
  322. yourDodge = 0; // uses up players dodge
  323. if (enemyNRG < 40)
  324. {
  325. enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
  326. }
  327. if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
  328. {
  329. yourHP -= normalDMG;
  330. cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
  331. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  332.  
  333. }
  334. else
  335. {
  336. cout << "The enemy tried using a normal attack but missed!" << endl;
  337. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  338.  
  339. }
  340. }
  341. }
  342. if (enemyrandomattack == 3 && enemyHP < 100) // enemy heal
  343. {
  344. enemyHP = enemyHP + (enemyNRG / 2);
  345. enemyNRG = (enemyNRG / 2);
  346. if (enemyHP > 100)
  347. {
  348. enemyHP = 100;
  349. }
  350. cout << "The enemy decided to heal!" << endl;
  351. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  352. }
  353.  
  354. if (enemyrandomattack == 4 && enemyDodge == 1) // if the enemy rolls a dodge action and already had dodge it will then use a normal attack
  355. {
  356. if (enemyNRG < 40)
  357. {
  358. enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
  359. if (enemyNRG > 40)
  360. {
  361. enemyNRG = 40; // if the enemy exceeds 40 energy then it sets it at 40
  362. }
  363. }
  364. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
  365. {
  366. if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting
  367. {
  368. yourHP -= normalDMG;
  369. cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
  370. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  371.  
  372. }
  373. else
  374. {
  375. cout << "The enemy tried using a normal attack but missed!" << endl;
  376. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  377. }
  378. }
  379. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  380. {
  381. yourDodge = 2; // uses up players dodge
  382. if (enemyNRG < 40)
  383. {
  384. enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
  385. if (enemyNRG > 40)
  386. {
  387. enemyNRG = 40;
  388. }
  389. }
  390. if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
  391. {
  392. yourHP -= normalDMG;
  393. cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
  394. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  395. }
  396. else
  397. {
  398. cout << "The enemy tried using a normal attack but missed!" << endl;
  399. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  400. }
  401. }
  402. if (enemyrandomattack == 4 && enemyDodge != 1) // the enemy will dodge if he doesn't have dodge already
  403. {
  404. enemyDodge = 1;
  405. if (enemyNRG < 40)
  406. {
  407. enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
  408. if (enemyNRG > 40)
  409. {
  410. enemyNRG = 40;
  411. }
  412. }
  413. cout << "The enemy decided to dodge the next attack!" << endl;
  414. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  415. }
  416.  
  417. }
  418.  
  419. if (enemyrandomattack == 5) // enemy recharge
  420. {
  421. if (enemyNRG < 40)
  422. {
  423. enemyNRG = 40;
  424. cout << "The enemy rests for a turn and regenerates it's energy... " << endl;
  425. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  426.  
  427. }
  428. if (enemyNRG == 40) // if the enemy generates this action and already has max energy he will then use a special attack instead
  429. {
  430. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss
  431. {
  432. if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting
  433. {
  434. yourHP -= specialDMG;
  435. cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
  436. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  437. enemyNRG = 10; // energy gained at the end of the turn
  438.  
  439. }
  440. else
  441. {
  442. enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10)
  443. cout << "The enemy tried using a special attack but missed!" << endl;
  444. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  445.  
  446. }
  447. }
  448. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  449. {
  450. yourDodge = 0; // uses up players dodge
  451. if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging
  452. {
  453. yourHP -= specialDMG;
  454. cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
  455. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  456. enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code
  457.  
  458. }
  459. else
  460. {
  461. cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl;
  462. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  463.  
  464. }
  465. }
  466. }
  467. }
  468. }
  469. else
  470. {
  471. if (enemyNRG < 40)
  472. {
  473. enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
  474. if (enemyNRG > 40)
  475. {
  476. enemyNRG = 40; //does not let the enemy exceed 40 energy
  477. }
  478. }
  479. if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
  480. {
  481. action = rand() % 9 + 1;
  482. if (action > 2) // the enemy has an 80% chance of hitting
  483. {
  484. normalDMG = rand() % 9 + 1;
  485. yourHP -= normalDMG;
  486. cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
  487. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  488.  
  489. }
  490. else
  491. {
  492. cout << "The enemy tried using a normal attack but missed!" << endl;
  493. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  494.  
  495. }
  496. }
  497. if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
  498. {
  499. yourDodge = 0; // uses up players dodge
  500. action = rand() % 9 + 1;
  501. if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
  502. {
  503. normalDMG = rand() % 9 + 1;
  504. yourHP -= normalDMG;
  505. cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
  506. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  507.  
  508. }
  509. else
  510. {
  511. cout << "The enemy tried using a normal attack but missed!" << endl;
  512. cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
  513. }
  514. }
  515.  
  516.  
  517. }
  518. } while (enemyHP > 0 && yourHP > 0); // the program runs while both creatures are alive
  519.  
  520. if (enemyHP <= 0)
  521. {
  522. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
  523. cout << "Congratulations, your creature won!!!";
  524. }
  525. if (yourHP <= 0)
  526. {
  527. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
  528. cout << "Your creature died and the enemy ate you...";
  529. }
  530. cin.clear();
  531. cin.ignore();
  532. _getch();
  533. return 0;
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement