Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <conio.h>
- #include<cmath>
- #include<cstdlib>
- #include"Header.h"
- using namespace std;
- #define ATTACK 1
- #define HEAL 2
- #define FALSE 0
- #define QUIT 9
- int main()
- {
- int phealth; //player health
- int ehealth; //enemy health
- int heal; //amount healed
- int pdam; //amount of damage dealt by player
- int edam; //amount of damage dealt by enemy
- int choice;
- int crit; //critical hit / miss chance (1 in 5 chance for each)
- phealth = 100;
- ehealth = 100;
- while (true) {
- cout << "Player HP: " << phealth << endl;
- cout << "Enemy HP: " << ehealth << endl;
- printf("Select an action... \n");
- printf("1.) Attack\n2.) Heal\n");
- cin >> choice;
- if (cin.fail()) {
- // purge keyboard buffer relics
- cin.clear(); // calm down 'cin' internal flags
- rewind(stdin); // clear out the actual keyboard corruption
- continue;
- }
- switch (choice)
- {
- case ATTACK:
- ClearScreen();
- SeedRNGToSystemClock();
- crit = generateRandomValue(1, 5);
- pdam = generateRandomValue(0, 10);
- if (crit == 1)
- {
- pdam = (pdam * 2.5) + 5;
- cout << "CRITICAL HIT!" << endl;
- }
- if (crit == 2)
- {
- pdam = pdam * 0;
- cout << "Your attack missed!" << endl;
- }
- ehealth -= pdam;
- edam = generateRandomValue(0, 10);
- phealth -= edam;
- cout << "You dealt " << pdam << " damage to opponent." << endl;
- cout << "Enemy dealt " << edam << " damage to you." << endl << endl;
- break;
- case HEAL:
- ClearScreen();
- SeedRNGToSystemClock();
- heal = generateRandomValue(3, 25);
- phealth += heal;
- edam = generateRandomValue(0, 10);
- phealth -= edam;
- cout << "You healed " << heal << " HP." << endl;
- cout << "Enemy dealt " << edam << " damage to you." << endl << endl;
- break;
- default:
- cout << "Incorrect input. Try again! \n";
- }
- } // end - while
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement