Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #include <string>
- #include <cstdlib>
- int hp = 100;
- int enemy = 100;
- int damage;
- int enemyDamage;
- int game = 1;
- int mana = 40;
- string action;
- int magicSwitch = 0;
- int main()
- {
- while (game > 0) {
- cout << "An enemy appears!" << endl;
- cout << "What will you do?" << endl;
- cout << "a(attack) i(inventory) s(spells) r(run): ";
- getline(cin, action);
- if (action == "a") {
- damage = rand() % 20;
- enemy = enemy - damage;
- if (damage == 0) {
- cout << "The enemy evaded your attack!" << endl;
- }
- cout << "You strike the enemy for " << damage << " damage"<<endl;
- enemyDamage = rand() % 15;
- cout << "The enemy strikes back for " << enemyDamage << " damage!" << endl;
- hp = hp - enemyDamage;
- }
- if (action == "i") {
- }
- if (hp <= 0) {
- cout << "Oh dear, you are dead!" << endl;
- game = game - 1;
- return 0;
- }
- if (enemy <= 0) {
- cout << "The enemy has been defeated!" << endl;
- game = game - 1;
- }
- if (action == "s" && mana >= 10) {
- cout << "Which spell do you wish to cast? (1-3)" << endl;
- cout << "1. Fireball (10 mana)." << endl;
- cout << "2. Magic missile! (15 mana)." << endl;
- cout << "3. Heal (20 mana)" << endl;
- cin >> magicSwitch;
- }
- switch (magicSwitch) {
- case 1: cout << "You cast Fireball!" << endl;
- enemy = enemy - damage * 2;
- mana = mana - 10;
- cout << enemy << endl;
- break;
- case 2: cout << "You cast Magic missile!" << endl;
- enemy = enemy - damage - enemy / 3;
- mana = mana - 15;
- cout << enemy << endl;
- break;
- case 3: cout << "You cast Heal!" << endl;
- hp = hp + damage;
- mana = mana - 20;
- cout << hp << endl;
- break;
- default: cout << "Which spell do you wish to cast? (1-3)" << endl;
- cout << "1. Fireball (10 mana)." << endl;
- cout << "2. Magic missile! (15 mana)." << endl;
- cout << "3. Heal (20 mana)" << endl;
- break;
- }
- if (mana < 10 && action == "s"){
- cout << "You don't have enough mana!" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement