Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. #include <iostream> //preprocessor directive
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string playerName, beastName, beastRank, choice;
  10. int beastGrade = 0;//1-60 is common, 61-80 is uncommon, 81-95 is rare, 96-100 is legendary
  11. 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
  12. cout << "Enter your player name and enter.\n"; //ask for the name of player
  13. getline(cin, playerName);
  14. cin.clear();
  15. int shop, shopLoop;
  16. int playerLevel = 1;
  17. int playerExtraDamage = 0;
  18. int playerExp = 0;
  19. int playerGold = 5;
  20. int playerGoldToGive = 0;
  21. int playerExpNeeded = 10;
  22. int playerHealth = 100;
  23. int playerMaxHealth = 100;
  24. int enemyHealth = 100;
  25. int playerPotionCount = 3;
  26. int gameContinue = 0;
  27. while (gameContinue == 0)
  28. {
  29. cin.clear();
  30. system("CLS");
  31. 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";
  32. cin >> choice;
  33. if (choice == "1")
  34. {
  35. system("CLS");
  36. srand(time(NULL));//sets random set to current time so always unique
  37. beastRandom = rand() % 100 + 1;
  38. beastGrade = rand() % 100 + 1;
  39. if (beastRandom >= 96 && beastRandom <= 100)
  40. {
  41. beastName = "dragon";
  42. playerGoldToGive = 100;
  43. }
  44. else if (beastRandom > 80 && beastRandom < 96)
  45. {
  46. beastName = "bandit";
  47. playerGoldToGive = 5;
  48. }
  49. else if (beastRandom >= 66 && beastRandom <= 80)
  50. {
  51. beastName = "skeleton";
  52. playerGoldToGive = 3;
  53. }
  54. else if (beastRandom >= 51 && beastRandom < 66)
  55. {
  56. beastName = "troll";
  57. playerGoldToGive = 7;
  58. }
  59. else if (beastRandom >= 36 && beastRandom < 51)
  60. {
  61. beastName = "goblin";
  62. playerGoldToGive = 2;
  63. }
  64. else if (beastRandom >= 21 && beastRandom < 36)
  65. {
  66. beastName = "slime";
  67. playerGoldToGive = 5;
  68. }
  69. else if (beastRandom >= 0 && beastRandom < 21)
  70. {
  71. beastName = "boar";
  72. playerGoldToGive = 1;
  73. }
  74. if (beastGrade >= 96 && beastGrade <= 100)
  75. {
  76. beastRank = "legendary";
  77. playerGoldToGive *= 5;
  78. }
  79. else if (beastGrade > 80 && beastGrade < 96)
  80. {
  81. beastRank = "rare";
  82. playerGoldToGive *= 3;
  83. }
  84. else if (beastGrade >= 61 && beastGrade <= 80)
  85. {
  86. beastRank = "uncommon";
  87. playerGoldToGive *= 2;
  88. }
  89. else if (beastGrade >= 0 && beastGrade < 61)
  90. {
  91. beastRank = "common";
  92. playerGoldToGive *= 1;
  93. }
  94. cout << "You've encountered a " << beastRank << " " << beastName << ". You've gained " << playerGoldToGive << " gold." << endl;
  95. playerGold += playerGoldToGive;
  96. system("pause");
  97. }
  98. else if (choice == "2")
  99. {
  100. system("CLS");
  101. shopLoop = 0;
  102. //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";
  103. //cin >> shop;
  104. while (shopLoop == 0)
  105. {
  106. system("CLS");
  107. 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 << 5 gold\n";
  108. cout << "[4] Pet Dragon +50 damage << 100 gold\n[5] Stamina potion << 5 Gold\n[6] Bronze Sword +20 damage << 60 Gold\n[7] Leave the shop\n";
  109. cin >> shop;
  110. if (shop == 1)
  111. {
  112. if (playerGold >= 5)
  113. {
  114. system("CLS");
  115. playerGold -= 5;
  116. playerPotionCount += 1;
  117. cout << "You've bought a Health potion.\n";
  118. system("pause");
  119. }
  120. else
  121. {
  122. system("CLS");
  123. cout << "You don't have enough money to buy a Health potion.\n";
  124. system("pause");
  125. }
  126. }
  127. else if (shop == 2)
  128. {
  129. if (playerExtraDamage == 0)
  130. {
  131. if (playerGold >= 30)
  132. {
  133. system("CLS");
  134. playerExtraDamage = 10;
  135. playerGold -= 30;
  136. cout << "You've bought a Steel Sword!. We are now out of stock.\n";
  137. system("pause");
  138. }
  139. else
  140. {
  141. system("CLS");
  142. cout << "You don't have enough money to buy the Steel Sword.\n";
  143. system("pause");
  144. }
  145. }
  146. else
  147. {
  148. system("CLS");
  149. cout << "You have already bought the Steel Sword. We are out of stock.\n";
  150. system("pause");
  151. }
  152. }
  153. else if (shop == 3)
  154. {
  155. if (playerExtraDamage >= 0)
  156. {
  157. if (playerGold >= 5)
  158. {
  159. system("CLS");
  160. playerGold -= 5;
  161. playerPotionCount += 1;
  162. playerExtraDamage += 1;
  163. cout << "You've purchased a Strength potion!\n";
  164. system("pause");
  165. }
  166. }
  167. else
  168. {
  169. system("CLS");
  170. cout << "You do not have enough currency for a Strength potion.\n";
  171. system("pause");
  172. }
  173. }
  174. else if (shop == 4)
  175. {
  176. if (playerExtraDamage < 50)
  177. {
  178. if (playerGold >= 100)
  179. {
  180. system("CLS");
  181. playerExtraDamage += 50;
  182. playerGold -= 100;
  183. cout << "You've purchased a pet dragon! We are out of stock\n";
  184. system("pause");
  185. }
  186. else
  187. {
  188. system("CLS");
  189. cout << "You do not have enough money for the pet dragon\n";
  190. system("pause");
  191. }
  192. }
  193. else
  194. {
  195. system("CLS");
  196. cout << "You have already bought the pet dragon. We longer have this.\n";
  197. system("pause");
  198. }
  199. }
  200. else if (shop == 5)
  201. {
  202. if (playerGold >= 5)
  203. {
  204. system("CLS");
  205. playerGold -= 5;
  206. playerPotionCount += 1;
  207. cout << "You have purchased a Stamina potion!\n";
  208. system("pause");
  209. }
  210. else
  211. {
  212. system("CLS");
  213. cout << "You do not have the required money for a Stamina potion.\n";
  214. system("pause");
  215. }
  216. }
  217. else if (shop == 6)
  218. {
  219. if (playerExtraDamage < 20)
  220. {
  221. if (playerGold >= 60)
  222. {
  223. system("CLS");
  224. playerExtraDamage += 20;
  225. playerGold -= 60;
  226. cout << "You've purchased a Bronze Sword! We are out of stock now.\n";
  227. system("pause");
  228. }
  229. else
  230. {
  231. system("CLS");
  232. cout << "You do not enough money for the Bronze Sword.\n";
  233. system("pause");
  234. }
  235. }
  236. else
  237. {
  238. system("CLS");
  239. cout << "You have already bought the Bronze Sword. There are no more available.\n";
  240. system("pause");
  241. }
  242. }
  243. else if (shop == 7)
  244. {
  245. system("CLS");
  246. shopLoop = 1;
  247. }
  248. }
  249. }
  250. else if (choice == "3")
  251. {
  252. system("CLS");
  253. cout << "Your stats:\nHealth: " << playerHealth << "/" << playerMaxHealth << endl;
  254. cout << "Level: " << playerLevel << endl;
  255. cout << "Gold: " << playerGold << endl;
  256. cout << "Potions: " << playerPotionCount << endl;
  257. cout << "Weapons and Equipment:\n";
  258. if (playerExtraDamage >= 10 && playerExtraDamage < 20)
  259. {
  260. cout << "-Steel Sword +10 Damage\n";
  261.  
  262. }
  263. else if (playerExtraDamage >= 20 && playerExtraDamage < 30)
  264. {
  265. cout << "-Bronze Sword +20 Damage\n";
  266. }
  267. else if (playerExtraDamage >= 30 && playerExtraDamage < 50)
  268. {
  269. cout << "-Steel Sword +10 Damage\n";
  270. cout << "-Bronze Sword +20 Damage\n";
  271. }
  272. else if (playerExtraDamage == 50)
  273. {
  274. cout << "-Pet Dragon +50 Damage\n";
  275. }
  276. else if (playerExtraDamage > 50)
  277. {
  278. cout << "-Steel Sword +10 Damage\n";
  279. cout << "-Bronze Sword +20 Damage\n";
  280. cout << "-Pet Dragon +50 Damage\n";
  281. }
  282. else
  283. {
  284. cout << "No weapons and/or equipment.\n";
  285. }
  286. system("pause");
  287. }
  288. else if (choice == "4")
  289. {
  290. system("CLS");
  291. gameContinue = 1;
  292. cout << "Thanks for playing!\n";
  293. }
  294. else
  295. {
  296. system("CLS");
  297. cout << "Invalid input.\n";
  298. system("pause");
  299.  
  300. }
  301. }
  302. system("pause");
  303. return 0;
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement