Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using namespace std;
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <cstdlib>
  6. int hp = 100;
  7. int enemy = 100;
  8. int damage;
  9. int enemyDamage;
  10. int game = 1;
  11. int mana = 40;
  12. string action;
  13. int magicSwitch = 0;
  14. int main()
  15. {
  16. while (game > 0) {
  17. cout << "An enemy appears!" << endl;
  18. cout << "What will you do?" << endl;
  19. cout << "a(attack) i(inventory) s(spells) r(run): ";
  20. getline(cin, action);
  21.  
  22. if (action == "a") {
  23. damage = rand() % 20;
  24. enemy = enemy - damage;
  25. if (damage == 0) {
  26. cout << "The enemy evaded your attack!" << endl;
  27. }
  28. cout << "You strike the enemy for " << damage << " damage"<<endl;
  29. enemyDamage = rand() % 15;
  30. cout << "The enemy strikes back for " << enemyDamage << " damage!" << endl;
  31. hp = hp - enemyDamage;
  32. }
  33. if (action == "i") {
  34.  
  35. }
  36. if (hp <= 0) {
  37. cout << "Oh dear, you are dead!" << endl;
  38. game = game - 1;
  39. return 0;
  40. }
  41. if (enemy <= 0) {
  42. cout << "The enemy has been defeated!" << endl;
  43. game = game - 1;
  44. }
  45. if (action == "s" && mana >= 10) {
  46. cout << "Which spell do you wish to cast? (1-3)" << endl;
  47. cout << "1. Fireball (10 mana)." << endl;
  48. cout << "2. Magic missile! (15 mana)." << endl;
  49. cout << "3. Heal (20 mana)" << endl;
  50. cin >> magicSwitch;
  51. }
  52. switch (magicSwitch) {
  53. case 1: cout << "You cast Fireball!" << endl;
  54. enemy = enemy - damage * 2;
  55. mana = mana - 10;
  56. cout << enemy << endl;
  57. break;
  58. case 2: cout << "You cast Magic missile!" << endl;
  59. enemy = enemy - damage - enemy / 3;
  60. mana = mana - 15;
  61. cout << enemy << endl;
  62. break;
  63. case 3: cout << "You cast Heal!" << endl;
  64. hp = hp + damage;
  65. mana = mana - 20;
  66. cout << hp << endl;
  67. break;
  68. default: cout << "Which spell do you wish to cast? (1-3)" << endl;
  69. cout << "1. Fireball (10 mana)." << endl;
  70. cout << "2. Magic missile! (15 mana)." << endl;
  71. cout << "3. Heal (20 mana)" << endl;
  72. break;
  73. }
  74. if (mana < 10 && action == "s"){
  75. cout << "You don't have enough mana!" << endl;
  76. }
  77. }
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement