Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Changes from 1.0 to 1.1:
- Cleaned up code
- Converted battles into functions
- Added levelup check (Doesn't do anything)
- Added gameover and win after battles
- Added Robot battle
- Added xp gain after battle won
- Changes from 1.1 to 1.2:
- Added Shop
- Added levels
- Added gold
- Added boost HP potions
- Changed defend into drink health potion + defend
- Added Pig and Patrick White battles.
- */
- #include <iostream>
- using namespace std;
- string name;
- string input;
- int loop;
- int attack = 10;
- int defence = 10;
- int health = 40;
- int points = 10;
- int maxhealth = 40;
- int xp;
- int win;
- int potion_number;
- int potion_boost;
- int level;
- int coins;
- int shop ()
- {
- int shopping;
- cout << string(30, '*') << "\n";
- cout << "Welcome to the shop!\n";
- cout << "You have " << coins << " gold\n";
- cout << "Would you like to:\n\n";
- cout << "Buy a health potion | 20g (a)\n";
- cout << "Buy a boost potion | 15g (d)\n";
- cout << "Leave (l)\n";
- shopping = 1;
- while (shopping == 1)
- {
- cin >> input;
- if (input == "a")
- {
- if (coins > 19)
- {
- potion_number = potion_number + 1;
- coins = coins - 20;
- cout << "You bought a health potion, you have " << coins << " gold left and "<< potion_number << " health potion(s). \n";
- }
- else
- {
- cout << "Not enough gold! \n";
- }
- }
- else if (input == "d")
- {
- if (coins > 14)
- {
- potion_boost = potion_boost + 1;
- coins = coins - 15;
- cout << "You bought a boost potion, you have " << coins << " gold left and "<< potion_boost << " boost potion(s). \n";
- }
- else
- {
- cout << "Not enough gold! \n";
- }
- }
- else if (input == "l")
- {
- shopping = 0;
- }
- else
- {
- cout << "Invalic input. \n";
- }
- }
- }
- int points_add ()
- {
- while (points > 0){
- cout << "\n\n\n";
- cout << "You have " << points << " points left to spend. \n \n";
- cout << "You have " << defence << " defence & " << attack << " attack. \n";
- cout << "Spend on defence (d) or attack (a)? \n";
- cin >> input;
- if (input == "d")
- {
- cout << "+1 Defence! \n";
- defence = defence +1;
- points = points -1;
- }
- else if (input == "a")
- {
- cout << "+1 Attack! \n";
- attack = attack +1;
- points = points -1;
- }
- else
- {
- cout << "Not a correct input.\n";
- }
- }
- cout << "\n\n";
- }
- int xpcheck ()
- {
- if (xp >= 30 && level < 1)
- {
- level = 1;
- points = points + 3;
- cout <<"LEVEL UP! You are now level " << level << ".\n";
- }
- if (xp >= 60 && level < 2)
- {
- level = 2;
- points = points + 3;
- cout <<"LEVEL UP! You are now level " << level << ".\n";
- }
- if (xp >= 100 && level < 3)
- {
- level = 3;
- points = points + 3;
- cout <<"LEVEL UP! You are now level " << level << ".\n";
- }
- }
- int fight (int enemyattack, int enemyhealth, string enemyname, int gain, int gold)
- {
- int boostcheck = 0;
- int battle = 1;
- int outcome;
- cout << "A wild " << enemyname << " appears!\n";
- cout << "It has: " << enemyhealth << " HP and " << enemyattack << " attack dmg. \n";
- // Start fight
- while (battle == 1)
- {
- cout << "You have " << health << " HP. \n";
- cout << "Do you attack (a), defend and drink a health potion (d), or drink a boost potion (s)?\n";
- cin >> input;
- if (input == "a")
- {
- if (boostcheck == 1)
- {
- enemyhealth = enemyhealth - attack*2,5;
- cout << "You attack for " << attack*2.5 << " damage! (2.5x Damage!!) The " << enemyname << " has " << enemyhealth << " HP left.\n";
- health = health - enemyattack;
- cout << "The enemy attacks you! You have " << health << " HP left.\n";
- boostcheck = 0;
- }
- else if (boostcheck == 0)
- {
- enemyhealth = enemyhealth - attack;
- cout << "You attack for " << attack << " damage! The " << enemyname << " has " << enemyhealth << " HP left.\n";
- health = health - enemyattack;
- cout << "The enemy attacks you! You have " << health << " HP left.\n";
- }
- }
- else if (input == "d")
- {
- cout << "You defend and drink a potion\n";
- if (potion_number > 0)
- {
- potion_number = potion_number -1;
- health = maxhealth;
- cout << "You drink a potion and your health is restored to " << health << ".\n";
- cout << "You have " << potion_number << " potions left. \n \n";
- }
- else
- {
- cout << "You have no more potions left \n";
- }
- if (defence > enemyattack)
- {
- health = health -1;
- }
- else if (defence < enemyattack)
- {
- health = health - (enemyattack - defence);
- }
- cout << "The enemy attacks you! You have " << health << " HP left.\n";
- }
- else if (input == "s")
- {
- if (potion_boost > 0)
- {
- potion_boost = potion_boost - 1;
- boostcheck = 1;
- cout << "You drank a boost potion, you have " << potion_boost << " left. Your next attack will do double damage. \n\n";
- if (defence > enemyattack)
- {
- health = health -1;
- }
- else if (defence < enemyattack)
- {
- health = health - (enemyattack - defence);
- }
- cout << "The enemy attacks you! You have " << health << " HP left.\n";
- }
- else
- {
- cout << "You do not have any boost potions \n";
- }
- }
- else
- {
- cout << "That is not a valid command. \n";
- }
- // Finish input, start check for HP.
- if (enemyhealth <1)
- {
- cout << "\n\nYou have defeated the " << enemyname << "!\n";
- battle = 0;
- xp = xp + gain;
- coins = coins + gold;
- 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";
- win = 1;
- }
- if (health <1)
- {
- cout << "\n\nYou have been DEFEATED by the " << enemyname << "!\n \n";
- battle = 0;
- win = 0;
- }
- // Finish check for HP
- }
- // Finish fight
- }
- int main()
- {
- cout << "Enter your name: \n";
- cin >> name;
- while (points > 0){
- cout << string(50, '\n');
- cout << "You have " << points << " points left to spend. \n \n";
- cout << "You have " << defence << " defence & " << attack << " attack. \n";
- cout << "Spend on defence (d) or attack (a)? \n";
- cin >> input;
- if (input == "d")
- {
- cout << "+1 Defence! \n";
- defence = defence +1;
- points = points -1;
- }
- else if (input == "a")
- {
- cout << "+1 Attack! \n";
- attack = attack +1;
- points = points -1;
- }
- else
- {
- cout << "Not a correct input.\n";
- }
- }
- potion_number = 3;
- health = defence*2 + health;
- maxhealth = defence*2 + maxhealth;
- cout << string(50, '\n');
- cout << "Your name is: " << name << "\nYou have " << defence << " defence, " << attack << " attack, and " << health <<" HP. \n \n";
- // End points setup stage.
- // Enter Battle 1.
- cout << string(30, '*') << "\n\n" ;
- string battle1;
- battle1 = fight (7, 38, "Knight",20,13);
- // Check if battle was won;
- if (win == 1)
- {
- cout << "You won the battle! \n \n";
- int battle1xp;
- battle1xp = xpcheck ();
- points_add ();
- loop = 1;
- while (loop == 1)
- {
- cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
- cin >> input;
- if (input == "a")
- {
- cout << "Entering shop. \n";
- loop = 0;
- shop ();
- }
- else if (input == "d")
- {
- cout << "Skipping shop. \n";
- loop =0;
- }
- else
- {
- cout << "Invalid input. \n";
- }
- }
- }
- else if (win == 0)
- {
- cout << "You lost the battle! \n" << "Game over. \n \n";
- return 0;
- }
- // End Battle 1.
- // Enter Battle 2.
- cout << string(30, '*') << "\n\n" ;
- string battle2;
- battle2 = fight (12, 45, "Robot", 23, 15);
- if (win == 1)
- {
- cout << "You won the battle! \n \n";
- int battle1xp;
- battle1xp = xpcheck ();
- points_add ();
- loop =1;
- while (loop == 1)
- {
- cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
- cin >> input;
- if (input == "a")
- {
- cout << "Entering shop. \n";
- loop = 0;
- shop ();
- }
- else if (input == "d")
- {
- cout << "Skipping shop. \n";
- loop =0;
- }
- else
- {
- cout << "Invalid input. \n";
- }
- }
- }
- else if (win == 0)
- {
- cout << "You lost the battle! \n" << "Game over. \n \n";
- return 0;
- }
- // End Battle 2
- // Enter Battle 3
- cout << string(30, '*') << "\n\n" ;
- string battle3;
- battle3 = fight (15, 55, "Patrick White", 25, 22);
- if (win == 1)
- {
- cout << "You won the battle! \n \n";
- int battle1xp;
- battle1xp = xpcheck ();
- points_add ();
- loop = 1;
- while (loop == 1)
- {
- cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
- cin >> input;
- if (input == "a")
- {
- cout << "Entering shop. \n";
- loop = 0;
- shop ();
- }
- else if (input == "d")
- {
- cout << "Skipping shop. \n";
- loop =0;
- }
- else
- {
- cout << "Invalid input. \n";
- }
- }
- }
- else if (win == 0)
- {
- cout << "You lost the battle! \n" << "Game over. \n \n";
- return 0;
- }
- // End Battle 3
- // Enter Battle 4
- cout << string(30, '*') << "\n\n" ;
- string battle4;
- battle4 = fight (10, 30, "Pig", 20, 19);
- if (win == 1)
- {
- cout << "You won the battle! \n \n";
- int battle1xp;
- battle1xp = xpcheck ();
- points_add ();
- loop = 1;
- while (loop == 1)
- {
- cout << "Would you like to vist the shop? Yes (a) or No (d) \n";
- cin >> input;
- if (input == "a")
- {
- cout << "Entering shop. \n";
- loop = 0;
- shop ();
- }
- else if (input == "d")
- {
- cout << "Skipping shop. \n";
- loop =0;
- }
- else
- {
- cout << "Invalid input. \n";
- }
- }
- }
- else if (win == 0)
- {
- cout << "You lost the battle! \n" << "Game over. \n \n";
- return 0;
- }
- // End Battle 4
- return 0;
- }
Add Comment
Please, Sign In to add comment