Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- int main()
- {
- int enemyHP = 100;
- int yourHP = 100;
- int enemyNRG = 40; //NRG stands for energy
- int yourNRG = 40;
- srand(time(NULL));
- int normalDMG = rand() % 9 + 1;
- int specialDMG = rand() % 15 + 5;
- int enemyrandomattack = rand() % 4 + 1; // random enemy action
- int input, n = 0;
- int enemyDodge = 0;
- int yourDodge = 0;
- int action;
- int runenemyattack = 1;
- enum actions
- {
- Attack = 1,
- SpecialAttack = 2,
- Heal = 3,
- Dodge = 4,
- Recharge = 5,
- };
- cout << "Welcome!" << endl;
- cout << "Press 1 for a normal attack (80% chance of hitting 1 - 10)" << endl;
- cout << "Press 2 for a special attack (50% chance of hitting 5 - 20)" << endl;
- cout << "Press 3 to use half of you current energy to heal for that amount" << endl;
- cout << "Press 4 to decrease the chance of the enemy hitting you by 30% next turn (decreases your energy regeneration by 50% this turn)" << endl;
- cout << "Press 5 to recharge your energy 4 times the rate but the enemy has a 10% higher chance of hitting you this turn" << endl << endl << endl;
- do {
- int HEALING = 0; // Lets the player to heal first and not use up the turn
- do
- {
- input = _getch() - '0';
- switch (input)
- {
- case Attack:
- if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss
- {
- if (yourNRG < 40)
- {
- yourNRG = (yourNRG + 10);
- if (yourNRG > 40)
- {
- yourNRG = 40;
- }
- }
- action = rand() % 9 + 1;
- if (action > 2) // the player has an 80% chance of hitting
- {
- normalDMG = rand() % 9 + 1;
- enemyHP -= normalDMG;
- cout << "You used a normal attack and did " << normalDMG << " damage!" << endl;
- HEALING = 2;
- break;
- }
- else
- {
- cout << "The player tried using a normal attack but missed!" << endl;
- HEALING = 2;
- break;
- }
- }
- if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing
- {
- if (yourNRG < 40)
- {
- yourNRG = (yourNRG + 10);
- if (yourNRG > 40)
- {
- yourNRG = 40;
- }
- enemyDodge = 0; // uses up the enemy's dodge
- action = rand() % 9 + 1;
- if (action > 5) // 50% chance of the player hitting a normal attack due to the enemy dodging
- {
- normalDMG = rand() % 9 + 1;
- enemyHP -= normalDMG;
- cout << "You used normal attack and did " << normalDMG << " damage!" << endl;
- HEALING = 2;
- break;
- }
- else
- {
- cout << "The player tried using a normal attack but missed!" << endl;
- HEALING = 2;
- break;
- }
- }
- break;
- }
- case SpecialAttack:
- if (yourNRG < 40)
- {
- cout << "You do not have enough energy to use a special attack!" << endl;
- HEALING = 0;
- break;
- }
- if (yourNRG == 40)
- {
- if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss
- {
- if (rand() % 9 + 1 > 5) // the player has a 50% chance of hitting
- {
- enemyHP -= specialDMG;
- cout << "You used a special attack and did " << specialDMG << " damage!" << endl;
- yourNRG = 10; // uses up 40 energy and then adds 10 at the end of the turn (saves lines of code) (40-40+10)
- HEALING = 2;
- break;
- }
- else
- {
- cout << "The player tried using a special attack but missed!" << endl;
- yourNRG = 10;
- HEALING = 2;
- break;
- }
- }
- if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing
- {
- enemyDodge = 0; // uses up the enemy's dodge
- if (rand() % 9 + 1 > 8) // 20% chance of the player hitting a special attack due to the enemy dodging
- {
- enemyHP -= specialDMG;
- cout << "You used a special attack and did " << specialDMG << " damage!" << endl;
- yourNRG = 10;
- HEALING = 2;
- break;
- }
- else
- {
- cout << "The player tried using a special attack but missed!" << endl;
- yourNRG = 10;
- HEALING = 2;
- break;
- }
- }
- }
- case Heal:
- if (HEALING == 0) // only lets the player heal as his first action and not use up the turn
- {
- yourHP += (yourNRG / 2);
- if (yourHP >= 100)
- {
- yourHP = 100;
- }
- cout << "Your creature healed itself and now has " << yourHP << " HP" << endl;
- HEALING++; //stops the player from healing twice in one turn, because HEALING will no longer be == 0
- break;
- }
- case Dodge:
- yourDodge = 1;
- if (yourNRG < 40)
- {
- yourNRG = (yourNRG + 5); // gains 5 instead of 10 because the energy gained per turn is halved by using dodge that turn
- if (yourNRG > 40)
- {
- yourNRG = 40; // does not let the player's energy exceed 40
- }
- }
- cout << "Your creature gets ready to evade the enemy" << endl;
- HEALING = 2;
- break;
- case Recharge:
- yourNRG = 40;
- cout << "Your creature recharged it's energy" << endl;
- HEALING = 2;
- break;
- default:
- cout << "Unknown action try 1-5" << endl;
- HEALING = 1;
- break;
- }
- } while (HEALING != 2); // The player's turn ends once he uses an action other than heal
- // The lines below are the enemy's actions
- enemyrandomattack = rand() % 4 + 1; // generates a random enemy action
- if (runenemyattack = 1)
- {
- if (enemyrandomattack == 1) // if the number one is randomly generated the enemy then does a normal attack
- {
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
- if (enemyNRG > 40)
- {
- enemyNRG = 40; //does not let the enemy exceed 40 energy
- }
- }
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
- {
- action = rand() % 9 + 1;
- if (action > 2) // the enemy has an 80% chance of hitting
- {
- normalDMG = rand() % 9 + 1;
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 0; // uses up players dodge
- action = rand() % 9 + 1;
- if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
- {
- normalDMG = rand() % 9 + 1;
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- }
- if (enemyrandomattack == 2 && enemyNRG < 40) // if a special attack action is generated and the enemy does not have max energy the enemy will then recharge instead
- {
- enemyNRG = 40;
- cout << "The enemy decided to rest for a turn and fully regenerated it's energy" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- if (enemyrandomattack == 2 && enemyNRG == 40) // enemy special attack
- {
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss
- {
- if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting
- {
- yourHP -= specialDMG;
- cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- enemyNRG = 10; // energy gained at the end of the turn
- }
- else
- {
- enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10)
- cout << "The enemy tried using a special attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 0; // uses up players dodge
- if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging
- {
- yourHP -= specialDMG;
- cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code
- }
- else
- {
- cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- }
- if (enemyrandomattack == 3 && enemyHP == 100) // if the enemy already had max hp and rolled the heal action he will then attack instead
- {
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
- if (enemyNRG > 40)
- {
- enemyNRG = 40; //does not let the enemy exceed 40 energy
- }
- }
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
- {
- if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting
- {
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 0; // uses up players dodge
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
- }
- if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
- {
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- }
- if (enemyrandomattack == 3 && enemyHP < 100) // enemy heal
- {
- enemyHP = enemyHP + (enemyNRG / 2);
- enemyNRG = (enemyNRG / 2);
- if (enemyHP > 100)
- {
- enemyHP = 100;
- }
- cout << "The enemy decided to heal!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- if (enemyrandomattack == 4 && enemyDodge == 1) // if the enemy rolls a dodge action and already had dodge it will then use a normal attack
- {
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
- if (enemyNRG > 40)
- {
- enemyNRG = 40; // if the enemy exceeds 40 energy then it sets it at 40
- }
- }
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
- {
- if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting
- {
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 2; // uses up players dodge
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
- if (enemyNRG > 40)
- {
- enemyNRG = 40;
- }
- }
- if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
- {
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (enemyrandomattack == 4 && enemyDodge != 1) // the enemy will dodge if he doesn't have dodge already
- {
- enemyDodge = 1;
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved
- if (enemyNRG > 40)
- {
- enemyNRG = 40;
- }
- }
- cout << "The enemy decided to dodge the next attack!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (enemyrandomattack == 5) // enemy recharge
- {
- if (enemyNRG < 40)
- {
- enemyNRG = 40;
- cout << "The enemy rests for a turn and regenerates it's energy... " << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- if (enemyNRG == 40) // if the enemy generates this action and already has max energy he will then use a special attack instead
- {
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss
- {
- if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting
- {
- yourHP -= specialDMG;
- cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- enemyNRG = 10; // energy gained at the end of the turn
- }
- else
- {
- enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10)
- cout << "The enemy tried using a special attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 0; // uses up players dodge
- if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging
- {
- yourHP -= specialDMG;
- cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code
- }
- else
- {
- cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- }
- }
- }
- else
- {
- if (enemyNRG < 40)
- {
- enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10
- if (enemyNRG > 40)
- {
- enemyNRG = 40; //does not let the enemy exceed 40 energy
- }
- }
- if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss
- {
- action = rand() % 9 + 1;
- if (action > 2) // the enemy has an 80% chance of hitting
- {
- normalDMG = rand() % 9 + 1;
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing
- {
- yourDodge = 0; // uses up players dodge
- action = rand() % 9 + 1;
- if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging
- {
- normalDMG = rand() % 9 + 1;
- yourHP -= normalDMG;
- cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- else
- {
- cout << "The enemy tried using a normal attack but missed!" << endl;
- cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl;
- }
- }
- }
- } while (enemyHP > 0 && yourHP > 0); // the program runs while both creatures are alive
- if (enemyHP <= 0)
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
- cout << "Congratulations, your creature won!!!";
- }
- if (yourHP <= 0)
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
- cout << "Your creature died and the enemy ate you...";
- }
- cin.clear();
- cin.ignore();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement