Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <time.h>
  4. using namespace std;
  5. void showTitle(), letsPlay(), pauseOutput();
  6. int whichSide(int charType), weaponDmgFunction(int weaponDmg), armorGivenFunction(int totalHealth);
  7. int playorQuit = 0, charType, weaponDmg = 0, charArmor, totalHealth, enemyHealth = 100, userChoice, enemyAttack, deathCounter = 0;
  8. int battleMenu(int userChoice), i, k = 0, userRemainingHP, continueFight(int j), j, a, b, gameOver(), defendAttack, defendRand;
  9. int attackOption(int enemyRemainingHP), enemyRemainingHP, attackUser(int userRemainingHP), attackFunctionHealth(int userRemainingHP);
  10.  
  11. int main()
  12. {
  13. do
  14. {
  15. showTitle();
  16. } while (playorQuit != 2);
  17.  
  18. cin.get();
  19. return 0;
  20. }
  21. void letsPlay()
  22. {
  23. int remainingHealth = totalHealth;
  24. string playerName;
  25.  
  26. cout << "\nHello! What is your name? \n";
  27. cin >> playerName;
  28. cout << "\nWelcome to the fight " << playerName << "! Let's get started. \n";
  29. charType = whichSide(charType);
  30. weaponDmg = weaponDmgFunction(weaponDmg);
  31. if (charType == 1) //berserker
  32. {
  33. cout << "\nYou have chosen to be a Berserker!\n";
  34. cout << "You notice a greatsword stuck in the ground. You pull with all your strength.\n"
  35. "It slides out easily. The earth quakes.\n"
  36. "You have been bestowed with the legendary Greatsword of Cuyamaca.\n"
  37. "It has an attack damage of " << weaponDmg << ".\n";
  38. }
  39. if (charType == 2) //tank
  40. {
  41. cout << "\nYou have chosen to be a Tank!\n";
  42. cout << "You notice a dusty chest in the middle of the darky-lit room. You advance.\n"
  43. "Inside of the chest lies an ancient crossbow.\n"
  44. "It has an attack damage of " << weaponDmg << ".\n";
  45. }
  46. totalHealth = armorGivenFunction(totalHealth);
  47. if (charType == 1)
  48. {
  49. cin.clear();
  50. pauseOutput();
  51. cout << "\Cuyamaca smiles upon you today. You are gifted with the royal armor of the family of Cuyamaca.\n"
  52. "May you prove yourself to the royal family.\n"
  53. "You fit in easily into the armor. It's lightweight, which allows you to handle the greatsword with ease.\n"
  54. "Your total health & armor points is " << totalHealth << ".\n";
  55. }
  56. if (charType == 2)
  57. {
  58. cin.clear();
  59. pauseOutput();
  60. cout << "\nYou find that the 'traitorous' family of Grossmont have left you very advanced, heavy armor.\n"
  61. "You struggle to put it on, but get acclimated to the weight very quickly. \n"
  62.  
  63. "Your total health & armor points is " << totalHealth << ".\n";
  64. }
  65. cin.clear();
  66. pauseOutput();
  67. cout << "You find a hidden trap door. You're feeling adventurous. You slowly descend down the ladder.\n"
  68. "You can barely see. However, you see a faint light off in the distance. You start to make your way towards it.\n"
  69. "You start to hear creatures squirming around.\n"
  70. "Suddenly...\n";
  71. cin.clear();
  72. pauseOutput();
  73. cout << "\nA STRANGE CREATURE APPEARS. It lunges forward at you! You barely dodge its attack.\n";
  74. userRemainingHP = attackUser(userRemainingHP);
  75. do
  76. {
  77. userChoice = battleMenu(userChoice);
  78. } while (enemyRemainingHP > 0 && userRemainingHP >0);
  79.  
  80. do
  81. {
  82. j = continueFight(j);
  83. } while (j == 1 && userRemainingHP > 0);
  84. if (j != 1)
  85. {
  86. int gold = deathCounter * 10;
  87. cout << "\nCongratulations on your victories today! You've been awarded " << gold << " pieces of gold!\n";
  88. }
  89. }
  90.  
  91. int continueFight(int j)
  92. {
  93. ++deathCounter;
  94. cout << "\nNice job! So far you've destroyed " << deathCounter << " enemies!\n"
  95. "Would you like to continue fighting?\n1. Yes\n2. No\n\n";
  96. cin.clear();
  97. cin >> j;
  98.  
  99. if (j == 1)
  100. {
  101. k = 0;
  102. enemyHealth += enemyHealth + (enemyHealth*.15);
  103. cout << "\nYou make your way down the pitch-dark cave. The light in the distance doesn't seem to be getting any closer.\n"
  104. "A STRANGER CREATURE APPEARS. It tries to bite you! You dodge its bite attack.\n";
  105. do {
  106. do
  107. {
  108. userChoice = battleMenu(userChoice);
  109. } while (enemyRemainingHP > 0 & userRemainingHP > 0);
  110. break;
  111. } while (j == 1);
  112. }
  113. return j;
  114. }
  115.  
  116.  
  117.  
  118.  
  119. int whichSide(int charType)
  120. {
  121.  
  122. cout << "\nFirst things first. What type of character would you like?\n1. Berserker\n2. Tank\n3. More info\n\n";
  123. cin >> charType;
  124. switch (charType)
  125. {
  126. case 1: //berserker
  127. break;
  128. case 2: //tank chosen
  129. break;
  130. case 3: //more info
  131. cout << "\n1. Berserkers have high attack damage, but low health.\n2. Tanks have very high health & armor, but low on damage.\nWhich would you like to choose?\n";
  132. cin >> charType;
  133. break;
  134. default: cout << "Please choose one of the available options\n";
  135. break;
  136. } //end of switch
  137.  
  138. return charType;
  139. }
  140. int weaponDmgFunction(int weaponDmg)
  141. {
  142.  
  143. if (charType == 1) //berserker
  144. {
  145. srand(time(0));
  146. int weaponDmg = 50 + (rand() * (80 - 50) / RAND_MAX);
  147. return weaponDmg;
  148. }
  149. if (charType == 2) //tank
  150. {
  151. srand(time(0));
  152. int weaponDmg = 25 + (rand() * (45 - 25) / RAND_MAX);
  153. return weaponDmg;
  154. }
  155. }
  156. int armorGivenFunction(int totalHealth)
  157. {
  158. if (charType == 1)
  159. {
  160. srand(time(0));
  161. int totalHealth = 150 + (rand() * (200 - 150) / RAND_MAX);
  162. return totalHealth;
  163.  
  164. }
  165. if (charType == 2)
  166. {
  167. srand(time(0));
  168. int totalHealth = 250 + (rand() * (300 - 250) / RAND_MAX);
  169. return totalHealth;
  170. }
  171. }
  172. int enemyAttackFunction(int enemyAttack)
  173. {
  174. if (a == 0)
  175. {
  176. enemyAttack = 25;
  177. ++a;
  178. return enemyAttack;
  179. }
  180. if (a > 0)
  181. {
  182. enemyAttack = enemyAttack + (enemyAttack*.07);
  183. ++a;
  184. return enemyAttack;
  185. }
  186.  
  187. }
  188. int battleMenu(int userChoice)
  189. {
  190. cout << "\nWhat would you like to do?\n1. Attack\n2. Defend\n3. Drink Potion\n\n";
  191. cin >> userChoice;
  192.  
  193. switch (userChoice)
  194. {
  195. case 1://attack
  196.  
  197. userRemainingHP = attackFunctionHealth(userRemainingHP);
  198. break;
  199. case 2://defend
  200. srand(time(0));
  201. defendRand = rand() & 11 + 1;
  202. userRemainingHP = attackUser(userRemainingHP);
  203. int blockedAttack;
  204. blockedAttack = userRemainingHP - defendAttack;
  205. enemyAttack = enemyAttackFunction(enemyAttack);
  206. if (defendRand >= 8)
  207. {
  208. defendAttack = enemyAttack - (enemyAttack*.75);
  209. cout << "\nYou grab your shield and manage to withstand most of the blow.\n"
  210. "You only get hit with " << defendAttack << " damage.\n"
  211. "Your remaining health is " << blockedAttack << ".\n";
  212.  
  213. }
  214. if (defendRand == 7)
  215. {
  216. defendAttack = enemyAttack * 0;
  217. cout << "\nYou manage to dodge their attack entirely!\n"
  218. "Your remaining health is " << blockedAttack << ".\n";
  219. }
  220. if (defendRand >= 1 && defendRand < 7)
  221. {
  222. defendAttack = enemyAttack - (enemyAttack*.25);
  223. cout << "\nYou were too slow. However you still somewhat protected yourself\n"
  224. "You take total damage of " << defendAttack << ".\nYour remaining health is " << blockedAttack << ".\n";
  225. }
  226. if (userRemainingHP <= 0)
  227. {
  228. gameOver();
  229. }
  230. break;
  231.  
  232. case 3://potion
  233. if (userRemainingHP > (totalHealth - (totalHealth*.15)))
  234. {
  235. cout << userRemainingHP;
  236. cout << totalHealth;
  237. int drinkPotion = (totalHealth*.15);
  238. userRemainingHP = attackUser(userRemainingHP);
  239. cout << "\nYou take a sip of a health-regenerating potion.\n"
  240. "\nYou gain " << drinkPotion << " healthpoints.\n"
  241. "\nYour total health is now " << userRemainingHP + drinkPotion << ".\n";
  242. }
  243. else
  244. {
  245. cout << userRemainingHP;
  246. cout << totalHealth;
  247. cout << "\nYour health is not low enough to drink a potion!\n";
  248. }
  249. break;
  250. }
  251. return userChoice;
  252. }
  253.  
  254. int attackFunctionHealth(int userRemainingHP)
  255. {
  256. enemyRemainingHP = attackOption(enemyRemainingHP);
  257. cout << "\nYou decide to attack the creature! You manage to to successfuly land an attack.\n"
  258. "You hit them for a total of " << weaponDmg << " hitpoints!\n";
  259. cout << "\nThe enemy has " << enemyRemainingHP << "/" << enemyHealth << " hitpoints left.\n";
  260. enemyAttack = enemyAttackFunction(enemyAttack);
  261. userRemainingHP = attackUser(userRemainingHP);
  262. cout << "\nThe enemy attacks you for a total of " << enemyAttack << " hitpoints. Your remaining health is " << userRemainingHP << ".\n";
  263. if (userRemainingHP <= 0)
  264. {
  265. gameOver();
  266. }
  267. return userRemainingHP;
  268. }
  269.  
  270.  
  271. int gameOver()
  272. {
  273. cout << "\n\nOH NO YOU'VE DIED!\n";
  274. return EXIT_SUCCESS;
  275. }
  276. int attackUser(int userRemainingHP)
  277. {
  278. if (b == 0)
  279. {
  280. userRemainingHP = totalHealth - enemyAttack;
  281. ++b;
  282. return userRemainingHP;
  283. }
  284. if (b > 0)
  285. {
  286. userRemainingHP = userRemainingHP - enemyAttack;
  287. ++b;
  288. return userRemainingHP;
  289. }
  290. }
  291. int attackOption(int enemyRemainingHP)
  292. {
  293. if (k == 0)
  294. {
  295. enemyRemainingHP = enemyHealth - weaponDmg;
  296. ++k;
  297. return enemyRemainingHP;
  298. }
  299. if (k > 0)
  300. {
  301. enemyRemainingHP = enemyRemainingHP - weaponDmg;
  302. ++k;
  303. return enemyRemainingHP;
  304. }
  305. }
  306. void pauseOutput()
  307. {
  308. cout << "\nPress enter to continue.\n";
  309. cin.ignore();
  310. cin.clear();
  311. cin.get();
  312. }
  313. void showTitle()
  314. {
  315. int runDebugger;
  316. cout << "\n -------- WELCOME TO CODE DUNGEON -------- "
  317. "\n Press enter to continue \n";
  318. cin.get();
  319. cout << "\nPlease choose one of the following options \n";
  320. cout << "1. Play \n2. Quit \n";
  321. cin >> playorQuit;
  322. switch (playorQuit)
  323. {
  324. case 1:
  325. letsPlay();
  326. break;
  327. case 2: cout << "\nGoodbye!\n";
  328. cin.get();
  329. break;
  330. case 99: //run secret test
  331.  
  332. cout << "Would you like to run the debugger?\n1. Yes\n2. No\n";
  333. cin >> runDebugger;
  334. if (runDebugger == 1)
  335. {
  336. cout << "Running debugger...\n";
  337.  
  338. cin.get();
  339. }
  340.  
  341. break;
  342. default: cout << "Please choose one of the available options. \n";
  343. break;
  344. }
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement