Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- int main()
- {
- int enemyHp = 50;
- int playerHp = 100;
- int playerChoice = 0;
- std::string waitForStart;
- std::cout << "You have encountered a rat, press enter to fight it" << std::endl;
- std::getline(std::cin, waitForStart); // waits for the user to press enter
- while (enemyHp > 0 && playerHp > 0) // Will as long as enemyHp AND playerHp > 0
- {
- std::cout << "Player Hp: " << playerHp << std::endl << std::endl;
- std::cout << "Enemy Hp: " << enemyHp << std::endl << std::endl;
- std::cout << "Press 0 for regular attack" << std::endl << std::endl;
- std::cout << "Press 1 for weak attack" << std::endl << std::endl;
- std::cin >> playerChoice;
- std::cin.ignore();
- if (playerChoice == 0) // Checks if the player wrote 0
- {
- enemyHp -= 5;
- std::cout << "You did a regular attack, dealing 5 damage" << std::endl;
- }
- else if (playerChoice == 1)
- {
- enemyHp -= 2;
- std::cout << "You did a weak attack, dealing 2 damage" << std::endl;
- }
- std::cout << "The enemy hits you, dealing 3 damage" << std::endl;
- playerHp -= 3;
- }
- if (enemyHp < 0)
- {
- std::cout << "You stand over the dead enemy victoriously" << std::endl;
- }
- else if (playerHp < 0)
- {
- std::cout << "The enemy defeats you" << std::endl;
- }
- std::cout << "Press enter to end the game" << std::endl;
- std::getline(std::cin, waitForStart); // waits for the user to press enter
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement