Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.85 KB | None | 0 0
  1. /*Dominic Grant, Muhammad Qureshi, Nathan Galdamez Gomez
  2. 03/21/2019
  3. Software Engineering Project*/
  4. #include <iostream> //preprocessor directive
  5. #include <iomanip>//preprocessor directive
  6. #include <cmath>//preprocessor directive
  7. #include <string>//preprocessor directive
  8. #include <cstdlib>//preprocessor directive
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. string playerName, beastName, beastRank, choice;
  14. int beastGrade = 0;//1-60 is common, 61-80 is uncommon, 81-95 is rare, 96-100 is legendary
  15. int beastRandom = 0;//1-20 is a boar, 21-35 is a slime, 36-50 is a goblin, 51-65 is a troll, 66-80 is a skeleton, 81-95 is a bandit, 96-100 is a dragon
  16. cout << "Enter your player name and enter.\n"; //ask for the name of playerene
  17. getline(cin, playerName);
  18. cin.clear();
  19. int shop, shopLoop;
  20. int playerLevel = 1;
  21. int playerBaseDamage = 5;
  22. int playerExtraDamage = 0;
  23. int playerExp = 0;
  24. int playerExpToGive = 0;
  25. int playerGold = 5;
  26. int playerGoldToGive = 0;
  27. int playerExpNeeded = 10;
  28. int playerHealth = 100;
  29. int playerMaxHealth = 100;
  30. int enemyHealth = 100;
  31. int playerPotionCount = 3;
  32. int dragonOwned = 0;
  33. int enemyAttack = 0;
  34. int gameContinue = 0;
  35.  
  36.  
  37.  
  38. while (gameContinue == 0)
  39. {
  40. //cin.clear();
  41. system("CLS");
  42. cout << "What do you want to do " << playerName << "?\n\n[1] Go adventuring.\n[2] Go to the shop.\n[3] See your stats and inventory.\n[4] End the game.\n";
  43. cin >> choice;
  44. if (choice == "1")
  45. {
  46. system("CLS");
  47. srand(time(NULL));//sets random set to current time so always unique
  48. beastRandom = rand() % 100 + 1;
  49. beastGrade = rand() % 100 + 1;
  50. if (beastRandom >= 96 && beastRandom <= 100)
  51. {
  52. beastName = "dragon";
  53. playerGoldToGive = 100;
  54. playerExpToGive = 75;
  55. enemyAttack = 50;
  56. enemyHealth = 150;
  57. }
  58. else if (beastRandom > 80 && beastRandom < 96)
  59. {
  60. beastName = "bandit";
  61. playerGoldToGive = 5;
  62. playerExpToGive = 15;
  63. enemyAttack = 15;
  64. enemyHealth = 60;
  65. }
  66. else if (beastRandom >= 66 && beastRandom <= 80)
  67. {
  68. beastName = "skeleton";
  69. playerGoldToGive = 3;
  70. playerExpToGive = 5;
  71. enemyAttack = 8;
  72. enemyHealth = 30;
  73. }
  74. else if (beastRandom >= 51 && beastRandom < 66)
  75. {
  76. beastName = "troll";
  77. playerGoldToGive = 7;
  78. playerExpToGive = 20;
  79. enemyAttack = 20;
  80. enemyHealth = 70;
  81. }
  82. else if (beastRandom >= 36 && beastRandom < 51)
  83. {
  84. beastName = "goblin";
  85. playerGoldToGive = 2;
  86. playerExpToGive = 3;
  87. enemyAttack = 5;
  88. enemyHealth = 20;
  89. }
  90. else if (beastRandom >= 21 && beastRandom < 36)
  91. {
  92. beastName = "slime";
  93. playerGoldToGive = 5;
  94. playerExpToGive = 3;
  95. enemyAttack = 5;
  96. enemyHealth = 10;
  97. }
  98. else if (beastRandom >= 0 && beastRandom < 21)
  99. {
  100. beastName = "boar";
  101. playerGoldToGive = 1;
  102. playerExpToGive = 5;
  103. enemyAttack = 5;
  104. enemyHealth = 15;
  105. }
  106. if (beastGrade >= 96 && beastGrade <= 100)
  107. {
  108. beastRank = "legendary";
  109. playerGoldToGive *= 5;
  110. playerExpToGive *= 3;
  111. enemyAttack *= 4;
  112. enemyHealth *= 4;
  113. }
  114. else if (beastGrade > 80 && beastGrade < 96)
  115. {
  116. beastRank = "rare";
  117. playerGoldToGive *= 3;
  118. playerExpToGive *= 2;
  119. enemyAttack *= 3;
  120. enemyHealth *= 3;
  121. }
  122. else if (beastGrade >= 61 && beastGrade <= 80)
  123. {
  124. beastRank = "uncommon";
  125. playerGoldToGive *= 2;
  126. playerExpToGive *= 1.5;
  127. enemyAttack *= 2;
  128. enemyHealth *= 2;
  129. }
  130. else if (beastGrade >= 0 && beastGrade < 61)
  131. {
  132. beastRank = "common";
  133. playerGoldToGive *= 1;
  134. }
  135. cout << "You've encountered a " << beastRank << " " << beastName << "." << endl;
  136. cout << "What do you want to do " << playerName << "?\n\n[1] Fight.\n[2] Run.\n";
  137. cin >> choice;
  138. //cout << "enemy health is: " << enemyHealth << endl;
  139. if (choice == "1") {
  140. //cout << "1 sword attack";
  141. //cin >> choice;
  142. cout << "enemy health is: " << enemyHealth << endl;
  143. string beastFullName = beastRank + " " + beastName;
  144.  
  145. int dragonCooldown = 0;
  146. int attackChoice = 0;
  147.  
  148. while (enemyHealth > 0 && playerHealth > 0)
  149. {
  150. cout << "\n\n Pick an attack: \n[1] Punch \n[2] Sword Slash.\n";
  151. if (dragonOwned == 1 && dragonCooldown == 0)
  152. {
  153. cout << "[3] Dragon attack \n" << endl;
  154. }
  155. if (playerPotionCount > 0)
  156. {
  157. cout << "[0] Health potion \n" << endl;
  158. }
  159. cin >> attackChoice;
  160. system("CLS");
  161. if (attackChoice == 1)
  162. {
  163.  
  164. enemyHealth = enemyHealth - playerBaseDamage;
  165. cout << "The enemy health is:" << enemyHealth << endl;
  166. dragonCooldown = 0;
  167. if (enemyHealth > 0)
  168. {
  169. cout << "The " << beastFullName << " attacks you and deals you " << enemyAttack << " damage." << endl;
  170. playerHealth -= enemyAttack;
  171. cout << "You now have " << playerHealth << " health remaining from your max health of " << playerMaxHealth << "." << endl;
  172. if (playerHealth <= 0)
  173. {
  174. cout << "You died to the monster. You resurrect at a church." << endl;
  175. }
  176. }
  177.  
  178. }
  179.  
  180. else if (attackChoice == 2)
  181. {
  182.  
  183. enemyHealth = enemyHealth - (playerBaseDamage + playerExtraDamage + 5);//5 is what im calling the damage for a basic beginner sword
  184. cout << "The enemy health is: " << enemyHealth << endl;
  185. dragonCooldown = 0;
  186. if (enemyHealth > 0)
  187. {
  188. cout << "The " << beastFullName << " attacks you and deals you " << enemyAttack << " damage." << endl;
  189. playerHealth -= enemyAttack;
  190. cout << "You now have " << playerHealth << " health remaining from your max health of " << playerMaxHealth << "." << endl;
  191. if (playerHealth <= 0)
  192. {
  193. cout << "You died to the monster. You resurrect at a church." << endl;
  194. }
  195. }
  196. }
  197. else if (attackChoice == 3 && dragonOwned == 1 && dragonCooldown == 0)
  198. {
  199.  
  200. enemyHealth = enemyHealth - 50;
  201. cout << "The enemy health is: " << enemyHealth << endl;
  202. dragonCooldown = 1;
  203. if (enemyHealth > 0)
  204. {
  205. cout << "The " << beastFullName << " attacks you and deals you " << enemyAttack << " damage." << endl;
  206. playerHealth -= enemyAttack;
  207. cout << "You now have " << playerHealth << " health remaining from your max health of " << playerMaxHealth << "." << endl;
  208. if (playerHealth <= 0)
  209. {
  210. cout << "You died to the monster. You resurrect at a church." << endl;
  211. }
  212. }
  213. }
  214. else if (attackChoice == 0 && playerPotionCount > 0)
  215. {
  216.  
  217. playerHealth += 50;
  218. if (playerHealth > playerMaxHealth)
  219. {
  220. playerHealth = playerMaxHealth;
  221. }
  222. cout << "Your health has increased by 50." << endl;
  223. cout << "The enemy health is: " << enemyHealth << endl;
  224. dragonCooldown = 0;
  225. if (enemyHealth > 0)
  226. {
  227. cout << "The " << beastFullName << " attacks you and deals you " << enemyAttack << " damage." << endl;
  228. playerHealth -= enemyAttack;
  229. cout << "You now have " << playerHealth << " health remaining from your max health of " << playerMaxHealth << "." << endl;
  230. if (playerHealth <= 0)
  231. {
  232. cout << "You died to the monster. You resurrect at a church." << endl;
  233. }
  234. }
  235. }
  236. else
  237. {
  238. cout << "Pick a valid option." << endl;
  239. }
  240.  
  241. }
  242. if (playerHealth > 0)
  243. {
  244. cout << beastFullName << " has been eliminated. You have gained " << playerGoldToGive << " gold." << endl;
  245. playerGold += playerGoldToGive;
  246. playerExp += playerExpToGive;
  247. cout << "You have gained " << playerExpToGive << " XP. Your current XP is : [" << playerExp << "/" << playerExpNeeded << "]" << endl;
  248. if (playerExp >= playerExpNeeded)
  249. {
  250. playerExp -= playerExpNeeded;
  251. playerLevel += 1;
  252. playerMaxHealth += 10;
  253. playerExpNeeded *= 2;
  254. playerHealth = playerMaxHealth;
  255. cout << "You have leveled up! You are now level " << playerLevel << ". Your health has been replenished and you now have a max health of " << playerMaxHealth << "." << endl;
  256. }
  257. cout << "Gold amount: \n" << playerGold << endl;
  258. }
  259. else
  260. {
  261. playerHealth = (playerMaxHealth / 2);
  262. }
  263. enemyHealth = 100;
  264. //cout <<"health right after fight after if loop" <<enemyHealth << endl;
  265. }
  266. else {
  267. cout << "you ran away...\n";
  268.  
  269.  
  270. }
  271. system("pause");
  272. }
  273. else if (choice == "2")
  274. {
  275. system("CLS");
  276. shopLoop = 0;
  277. //cout << "You've come to the shop. There's several items on display.\n\n[1] Health potion << 5 Gold\n[2] Steel Sword +10 damage << 30 Gold\n[3] Leave the Shop\n";
  278. //cin >> shop;
  279. while (shopLoop == 0)
  280. {
  281. system("CLS");
  282. cout << "You've come to the shop. There's several items on display.\n\n[1] Health potion << 5 Gold\n[2] Steel Sword +10 damage << 30 Gold\n[3] Strength potion. Increases base attack by 2 << 25 gold\n";
  283. cout << "[4] Pet Dragon. Battle option to do 50 damage. 1 turn cooldown << 100 gold\n[5] XP potion. Gives 50 XP<< 25 Gold\n[6] Bronze Sword +20 damage << 60 Gold\n[7] Leave the shop\n";
  284. cin >> shop;
  285. if (shop == 1)
  286. {
  287. if (playerGold >= 5)
  288. {
  289. system("CLS");
  290. playerGold -= 5;
  291. playerPotionCount += 1;
  292. cout << "You've bought a Health potion.\n";
  293. system("pause");
  294. }
  295. else
  296. {
  297. system("CLS");
  298. cout << "You don't have enough money to buy a Health potion.\n";
  299. system("pause");
  300. }
  301. }
  302. else if (shop == 2)
  303. {
  304. if (playerExtraDamage == 0)
  305. {
  306. if (playerGold >= 30)
  307. {
  308. system("CLS");
  309. playerExtraDamage = 10;
  310. playerGold -= 30;
  311. cout << "You've bought a Steel Sword!. We are now out of stock.\n";
  312. system("pause");
  313. }
  314. else
  315. {
  316. system("CLS");
  317. cout << "You don't have enough money to buy the Steel Sword.\n";
  318. system("pause");
  319. }
  320. }
  321. else
  322. {
  323. system("CLS");
  324. cout << "You have already bought the Steel Sword. We are out of stock.\n";
  325. system("pause");
  326. }
  327. }
  328. else if (shop == 3)
  329. {
  330. if (playerGold >= 25)
  331. {
  332. system("CLS");
  333. playerGold -= 25;
  334. cout << "You've purchased a Strength potion!\n";
  335. cout << "Your base attack has increased by 2\n";
  336. playerBaseDamage += 2;
  337. system("pause");
  338. }
  339. else
  340. {
  341. system("CLS");
  342. cout << "You do not have enough currency for a Strength potion.\n";
  343. system("pause");
  344. }
  345. }
  346. else if (shop == 4)
  347. {
  348. if (dragonOwned == 0)
  349. {
  350. if (playerGold >= 100)
  351. {
  352. system("CLS");
  353. dragonOwned = 1;
  354. playerGold -= 100;
  355. cout << "You've purchased the pet dragon! We are out of stock\n";
  356. system("pause");
  357. }
  358. else
  359. {
  360. system("CLS");
  361. cout << "You do not have enough money for the pet dragon\n";
  362. system("pause");
  363. }
  364. }
  365. else
  366. {
  367. system("CLS");
  368. cout << "You have already bought the pet dragon. We longer have this.\n";
  369. system("pause");
  370. }
  371. }
  372. else if (shop == 5)
  373. {
  374. if (playerGold >= 25)
  375. {
  376. system("CLS");
  377. playerGold -= 25;
  378. cout << "You have purchased a XP potion!\n";
  379. cout << "You have gained 50 XP\n";
  380. playerExp += 50;
  381. system("pause");
  382. }
  383. else
  384. {
  385. system("CLS");
  386. cout << "You do not have the required money for a XP potion.\n";
  387. system("pause");
  388. }
  389. }
  390. else if (shop == 6)
  391. {
  392. if (playerExtraDamage <= 20)
  393. {
  394. if (playerGold >= 60)
  395. {
  396. system("CLS");
  397. playerExtraDamage += 20;
  398. playerGold -= 60;
  399. cout << "You've purchased a Bronze Sword! We are out of stock now.\n";
  400. system("pause");
  401. }
  402. else
  403. {
  404. system("CLS");
  405. cout << "You do not enough money for the Bronze Sword.\n";
  406. system("pause");
  407. }
  408. }
  409. else
  410. {
  411. system("CLS");
  412. cout << "You have already bought the Bronze Sword. There are no more available.\n";
  413. system("pause");
  414. }
  415. }
  416. else if (shop == 7)
  417. {
  418. system("CLS");
  419. shopLoop = 1;
  420. }
  421. }
  422. }
  423. else if (choice == "3")
  424. {
  425. system("CLS");
  426. cout << "Your stats:\nHealth: " << playerHealth << "/" << playerMaxHealth << endl;
  427. cout << "Level: " << playerLevel << endl;
  428. cout << "Gold: " << playerGold << endl;
  429. cout << "Potions: " << playerPotionCount << endl;
  430. cout << "Weapons and Equipment:\n";
  431. if (playerExtraDamage >= 10 && playerExtraDamage < 20 && dragonOwned == 0)
  432. {
  433. cout << "-Steel Sword +10 Damage\n";
  434.  
  435. }
  436. else if (playerExtraDamage >= 20 && playerExtraDamage < 30 && dragonOwned == 0)
  437. {
  438. cout << "-Bronze Sword +20 Damage\n";
  439. }
  440. else if (playerExtraDamage == 30 && dragonOwned == 0)
  441. {
  442. cout << "-Steel Sword +10 Damage\n";
  443. cout << "-Bronze Sword +20 Damage\n";
  444. }
  445. else if (playerExtraDamage == 0 && dragonOwned == 1)
  446. {
  447. cout << "-Pet Dragon +50 Damage\n";
  448. }
  449. else if (playerExtraDamage == 10 && dragonOwned == 0)
  450. {
  451. cout << "-Steel Sword +10 Damage\n";
  452. cout << "-Pet Dragon +50 Damage\n";
  453. }
  454. else if (playerExtraDamage == 20 && dragonOwned == 0)
  455. {
  456. cout << "-Bronze Sword +20 Damage\n";
  457. cout << "-Pet Dragon +50 Damage\n";
  458. }
  459. else if (playerExtraDamage == 30 && dragonOwned == 0)
  460. {
  461. cout << "-Steel Sword +10 Damage\n";
  462. cout << "-Bronze Sword +20 Damage\n";
  463. cout << "-Pet Dragon +50 Damage\n";
  464. }
  465. else
  466. {
  467. cout << "No weapons and/or equipment.\n";
  468. }
  469. system("pause");
  470. }
  471. else if (choice == "4")
  472. {
  473. system("CLS");
  474. gameContinue = 1;
  475. cout << "Thanks for playing!\n";
  476. }
  477. else
  478. {
  479. system("CLS");
  480. cout << "Invalid input.\n";
  481. system("pause");
  482.  
  483. }
  484. }
  485. system("pause");
  486. return 0;
  487. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement