Advertisement
Aphenon

Turnbased combat

Aug 31st, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. int enemyHp = 50;
  7. int playerHp = 100;
  8. int playerChoice = 0;
  9. std::string waitForStart;
  10.  
  11. std::cout << "You have encountered a rat, press enter to fight it" << std::endl;
  12. std::getline(std::cin, waitForStart); // waits for the user to press enter
  13.  
  14. while (enemyHp > 0 && playerHp > 0) // Will as long as enemyHp AND playerHp > 0
  15. {
  16. std::cout << "Player Hp: " << playerHp << std::endl << std::endl;
  17. std::cout << "Enemy Hp: " << enemyHp << std::endl << std::endl;
  18. std::cout << "Press 0 for regular attack" << std::endl << std::endl;
  19. std::cout << "Press 1 for weak attack" << std::endl << std::endl;
  20.  
  21.  
  22. std::cin >> playerChoice;
  23. std::cin.ignore();
  24.  
  25. if (playerChoice == 0) // Checks if the player wrote 0
  26. {
  27. enemyHp -= 5;
  28. std::cout << "You did a regular attack, dealing 5 damage" << std::endl;
  29. }
  30. else if (playerChoice == 1)
  31. {
  32. enemyHp -= 2;
  33. std::cout << "You did a weak attack, dealing 2 damage" << std::endl;
  34. }
  35.  
  36. std::cout << "The enemy hits you, dealing 3 damage" << std::endl;
  37. playerHp -= 3;
  38. }
  39.  
  40. if (enemyHp < 0)
  41. {
  42. std::cout << "You stand over the dead enemy victoriously" << std::endl;
  43. }
  44. else if (playerHp < 0)
  45. {
  46. std::cout << "The enemy defeats you" << std::endl;
  47. }
  48. std::cout << "Press enter to end the game" << std::endl;
  49. std::getline(std::cin, waitForStart); // waits for the user to press enter
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement