Advertisement
Guest User

Untitled

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