Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.37 KB | None | 0 0
  1. /*
  2. Changes from 1.0 to 1.1:
  3.         Cleaned up code
  4.         Converted battles into functions
  5.         Added levelup check (Doesn't do anything)
  6.         Added gameover and win after battles
  7.         Added Robot battle
  8.         Added xp gain after battle won
  9.  
  10. Changes from 1.1 to 1.2:
  11.     Added Shop
  12.     Added levels
  13.     Added gold
  14.     Added boost HP potions
  15.     Changed defend into drink health potion + defend
  16.     Added Pig and Patrick White battles.
  17.    
  18. */
  19.  
  20.  
  21.     #include <iostream>
  22.  
  23.     using namespace std;
  24.  
  25.     string name;
  26.  
  27.     string input;
  28.     int loop;
  29.     int attack = 10;
  30.     int defence = 10;
  31.     int health = 40;
  32.     int points = 10;
  33.     int maxhealth = 40;
  34.     int xp;
  35.     int win;
  36.     int potion_number;
  37.     int potion_boost;
  38.     int level;
  39.     int coins;
  40.  
  41.  
  42. int shop ()
  43. {
  44.     int shopping;
  45.     cout << string(30, '*') << "\n";
  46.     cout << "Welcome to the shop!\n";
  47.     cout << "You have " << coins << " gold\n";
  48.     cout << "Would you like to:\n\n";
  49.     cout << "Buy a health potion | 20g (a)\n";
  50.     cout << "Buy a boost potion | 15g (d)\n";
  51.     cout << "Leave (l)\n";
  52.     shopping = 1;
  53.     while (shopping == 1)
  54.     {
  55.         cin >> input;
  56.     if (input == "a")
  57.     {
  58.         if (coins > 19)
  59.         {
  60.             potion_number = potion_number + 1;
  61.             coins = coins - 20;
  62.             cout << "You bought a health potion, you have " << coins << " gold left and "<< potion_number <<  " health potion(s). \n";
  63.         }
  64.         else
  65.         {
  66.             cout << "Not enough gold! \n";
  67.         }
  68.     }
  69.     else if (input == "d")
  70.     {
  71.         if (coins > 14)
  72.         {
  73.             potion_boost = potion_boost + 1;
  74.             coins = coins - 15;
  75.             cout << "You bought a boost potion, you have " << coins << " gold left and "<< potion_boost <<  " boost potion(s). \n";
  76.         }
  77.         else
  78.         {
  79.             cout << "Not enough gold! \n";
  80.         }
  81.     }
  82.     else if (input == "l")
  83.     {
  84.         shopping = 0;
  85.     }
  86.     else
  87.     {
  88.         cout << "Invalic input. \n";
  89.     }
  90.     }
  91. }
  92.  
  93.  
  94. int points_add ()
  95. {
  96.  while (points > 0){
  97.     cout << "\n\n\n";
  98.     cout << "You have " << points << " points left to spend. \n \n";
  99.     cout << "You have " << defence << " defence & " << attack << " attack. \n";
  100.     cout << "Spend on defence (d) or attack (a)? \n";
  101.     cin >> input;
  102.  
  103.     if (input == "d")
  104.     {
  105.         cout << "+1 Defence! \n";
  106.         defence = defence +1;
  107.         points = points -1;
  108.     }
  109.     else if (input == "a")
  110.     {
  111.         cout << "+1 Attack! \n";
  112.         attack = attack +1;
  113.         points = points -1;
  114.     }
  115.     else
  116.     {
  117.         cout << "Not a correct input.\n";
  118.     }
  119.  
  120.     }
  121. cout << "\n\n";
  122. }
  123.  
  124. int xpcheck ()
  125. {
  126.     if (xp >= 30 && level < 1)
  127.     {
  128.         level = 1;
  129.         points = points + 3;
  130.         cout <<"LEVEL UP! You are now level " << level << ".\n";
  131.     }
  132.         if (xp >= 60 && level < 2)
  133.     {
  134.         level = 2;
  135.         points = points + 3;
  136.         cout <<"LEVEL UP! You are now level " << level << ".\n";
  137.     }
  138.         if (xp >= 100 && level < 3)
  139.     {
  140.         level = 3;
  141.         points = points + 3;
  142.         cout <<"LEVEL UP! You are now level " << level << ".\n";
  143.     }
  144.  
  145. }
  146.     int fight (int enemyattack, int enemyhealth, string enemyname, int gain, int gold)
  147. {
  148.     int boostcheck = 0;
  149.     int battle = 1;
  150.     int outcome;
  151.     cout << "A wild " << enemyname << " appears!\n";
  152.     cout << "It has: " << enemyhealth << " HP and " << enemyattack << " attack dmg. \n";
  153. // Start fight
  154. while (battle == 1)
  155. {
  156.     cout << "You have " << health << " HP. \n";
  157.     cout << "Do you attack (a), defend and drink a health potion (d), or drink a boost potion (s)?\n";
  158.  
  159.     cin >> input;
  160.     if (input == "a")
  161. {
  162.     if (boostcheck == 1)
  163.     {
  164.     enemyhealth = enemyhealth - attack*2,5;
  165.     cout << "You attack for " << attack*2.5 << " damage! (2.5x Damage!!) The " << enemyname << " has " << enemyhealth << " HP left.\n";
  166.     health = health - enemyattack;
  167.     cout << "The enemy attacks you! You have " << health << " HP left.\n";
  168.     boostcheck = 0;
  169.     }
  170.     else if (boostcheck == 0)
  171.     {
  172.     enemyhealth = enemyhealth - attack;
  173.     cout << "You attack for " << attack << " damage! The " << enemyname << " has " << enemyhealth << " HP left.\n";
  174.     health = health - enemyattack;
  175.     cout << "The enemy attacks you! You have " << health << " HP left.\n";
  176.     }
  177. }
  178. else if (input == "d")
  179. {
  180.     cout << "You defend and drink a potion\n";
  181.  
  182.     if (potion_number > 0)
  183.     {
  184.     potion_number = potion_number -1;
  185.     health = maxhealth;
  186.  
  187.     cout << "You drink a potion and your health is restored to " << health << ".\n";
  188.     cout << "You have " << potion_number << " potions left. \n \n";
  189.     }
  190.     else
  191.     {
  192.         cout << "You have no more potions left \n";
  193.     }
  194.  
  195.     if (defence > enemyattack)
  196.     {
  197.         health = health -1;
  198.     }
  199.     else if (defence < enemyattack)
  200.     {
  201.         health = health - (enemyattack - defence);
  202.     }
  203.     cout << "The enemy attacks you! You have " << health << " HP left.\n";
  204. }
  205. else if (input == "s")
  206. {
  207.     if (potion_boost > 0)
  208.     {
  209.         potion_boost = potion_boost - 1;
  210.         boostcheck = 1;
  211.         cout << "You drank a boost potion, you have " << potion_boost << " left. Your next attack will do double damage. \n\n";
  212.             if (defence > enemyattack)
  213.     {
  214.         health = health -1;
  215.     }
  216.     else if (defence < enemyattack)
  217.     {
  218.         health = health - (enemyattack - defence);
  219.     }
  220.     cout << "The enemy attacks you! You have " << health << " HP left.\n";
  221.     }
  222.     else
  223.     {
  224.         cout << "You do not have any boost potions \n";
  225.     }
  226. }
  227. else
  228. {
  229.     cout << "That is not a valid command. \n";
  230. }
  231. // Finish input, start check for HP.
  232. if (enemyhealth <1)
  233. {
  234.     cout << "\n\nYou have defeated the " << enemyname << "!\n";
  235.     battle = 0;
  236.     xp = xp + gain;
  237.     coins = coins + gold;
  238.     cout << "You have gained " << gain << " XP and now have " << xp  << " total XP. \n"<< "You have gained " << gold << " gold. You now have " << coins << " total gold. \n\n";
  239.     win = 1;
  240. }
  241. if (health <1)
  242. {
  243.     cout << "\n\nYou have been DEFEATED by the " << enemyname << "!\n \n";
  244.     battle = 0;
  245.     win = 0;
  246. }
  247. // Finish check for HP
  248. }
  249. // Finish fight
  250.  
  251. }
  252.  
  253.     int main()
  254.     {
  255.     cout << "Enter your name: \n";
  256.     cin >> name;
  257.  
  258.     while (points > 0){
  259.     cout << string(50, '\n');
  260.     cout << "You have " << points << " points left to spend. \n \n";
  261.     cout << "You have " << defence << " defence & " << attack << " attack. \n";
  262.     cout << "Spend on defence (d) or attack (a)? \n";
  263.     cin >> input;
  264.  
  265.     if (input == "d")
  266.     {
  267.         cout << "+1 Defence! \n";
  268.         defence = defence +1;
  269.         points = points -1;
  270.     }
  271.     else if (input == "a")
  272.     {
  273.         cout << "+1 Attack! \n";
  274.         attack = attack +1;
  275.         points = points -1;
  276.     }
  277.     else
  278.     {
  279.         cout << "Not a correct input.\n";
  280.     }
  281.  
  282.     }
  283.     potion_number = 3;
  284.     health = defence*2 + health;
  285.     maxhealth = defence*2 + maxhealth;
  286.     cout << string(50, '\n');
  287.     cout << "Your name is: " << name << "\nYou have " << defence << " defence, " << attack << " attack, and " << health <<" HP. \n \n";
  288.  
  289.  
  290.     // End points setup stage.
  291.     // Enter Battle 1.
  292. cout << string(30, '*') << "\n\n" ;
  293. string battle1;
  294. battle1 = fight (7, 38, "Knight",20,13);
  295. // Check if battle was won;
  296. if (win == 1)
  297. {
  298.     cout << "You won the battle! \n \n";
  299.     int battle1xp;
  300.     battle1xp = xpcheck ();
  301.     points_add ();
  302.     loop = 1;
  303.     while (loop == 1)
  304.     {
  305.     cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
  306.     cin >> input;
  307.     if (input == "a")
  308.     {
  309.         cout << "Entering shop. \n";
  310.         loop = 0;
  311.         shop ();
  312.     }
  313.     else if (input == "d")
  314.     {
  315.         cout << "Skipping shop. \n";
  316.         loop =0;
  317.     }
  318.     else
  319.     {
  320.         cout << "Invalid input. \n";
  321.     }
  322.  
  323.     }
  324. }
  325. else if (win == 0)
  326. {
  327.     cout << "You lost the battle! \n" << "Game over. \n \n";
  328.     return 0;
  329. }
  330.     // End Battle 1.
  331.     // Enter Battle 2.
  332. cout << string(30, '*') << "\n\n" ;
  333. string battle2;
  334. battle2 = fight (12, 45, "Robot", 23, 15);
  335. if (win == 1)
  336. {
  337.     cout << "You won the battle! \n \n";
  338.     int battle1xp;
  339.     battle1xp = xpcheck ();
  340.     points_add ();
  341.     loop =1;
  342.     while (loop == 1)
  343.     {
  344.     cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
  345.     cin >> input;
  346.     if (input == "a")
  347.     {
  348.         cout << "Entering shop. \n";
  349.         loop = 0;
  350.         shop ();
  351.     }
  352.     else if (input == "d")
  353.     {
  354.         cout << "Skipping shop. \n";
  355.         loop =0;
  356.     }
  357.     else
  358.     {
  359.         cout << "Invalid input. \n";
  360.     }
  361.  
  362.     }
  363.  
  364. }
  365. else if (win == 0)
  366. {
  367.     cout << "You lost the battle! \n" << "Game over. \n \n";
  368.     return 0;
  369. }
  370. // End Battle 2
  371. // Enter Battle 3
  372. cout << string(30, '*') << "\n\n" ;
  373. string battle3;
  374. battle3 = fight (15, 55, "Patrick White", 25, 22);
  375. if (win == 1)
  376. {
  377.     cout << "You won the battle! \n \n";
  378.     int battle1xp;
  379.     battle1xp = xpcheck ();
  380.     points_add ();
  381.     loop = 1;
  382.         while (loop == 1)
  383.     {
  384.     cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
  385.     cin >> input;
  386.     if (input == "a")
  387.     {
  388.         cout << "Entering shop. \n";
  389.         loop = 0;
  390.         shop ();
  391.     }
  392.     else if (input == "d")
  393.     {
  394.         cout << "Skipping shop. \n";
  395.         loop =0;
  396.     }
  397.     else
  398.     {
  399.         cout << "Invalid input. \n";
  400.     }
  401.  
  402.     }
  403. }
  404. else if (win == 0)
  405. {
  406.     cout << "You lost the battle! \n" << "Game over. \n \n";
  407.     return 0;
  408. }
  409. // End Battle 3
  410. // Enter Battle 4
  411. cout << string(30, '*') << "\n\n" ;
  412. string battle4;
  413. battle4 = fight (10, 30, "Pig", 20, 19);
  414. if (win == 1)
  415. {
  416.     cout << "You won the battle! \n \n";
  417.     int battle1xp;
  418.     battle1xp = xpcheck ();
  419.     points_add ();
  420.     loop = 1;
  421.         while (loop == 1)
  422.     {
  423.     cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
  424.     cin >> input;
  425.     if (input == "a")
  426.     {
  427.         cout << "Entering shop. \n";
  428.         loop = 0;
  429.         shop ();
  430.     }
  431.     else if (input == "d")
  432.     {
  433.         cout << "Skipping shop. \n";
  434.         loop =0;
  435.     }
  436.     else
  437.     {
  438.         cout << "Invalid input. \n";
  439.     }
  440.  
  441.     }
  442. }
  443. else if (win == 0)
  444. {
  445.     cout << "You lost the battle! \n" << "Game over. \n \n";
  446.     return 0;
  447. }
  448. // End Battle 4
  449.     return 0;
  450.     }
Add Comment
Please, Sign In to add comment