Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <ctime>
- using namespace std;
- int dealDamage(int, int);
- int actualDamage(int);
- int randomNumber();
- int Fight(int, int, int, int, bool, string, int);
- int main() {
- bool playerIsAlive;
- int gold = 0;
- int skillPoints = 0;
- int healthPotions = 0;
- int playerHealth = 100;
- int playerDamage = 25;
- int wolfHealth = 100;
- int wolfDamage = 15;
- if (Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, playerIsAlive = true, "Wolf", healthPotions = 3) == true) {
- gold += 100;
- skillPoints += 1;
- cout << "____________________________________________________________" << endl;
- cout << "Well Done, you gained " << gold << " Gold and " << skillPoints << " Skill Points" << endl;
- }
- else {
- cout << "Baah NOOB!" << endl;
- }
- }
- int Fight(int hp1, int hp2, int dmg1, int dmg2, bool status, string enemyName, int healthPotion) {// 1. Player 2. Enemy
- int turn = 1;//this decides wether it's players turn or not
- int fightStatus; // if fight is won or lost
- int maxEnemyHealth = hp2; // gives us max hp of an enemy
- char playerMove;
- dmg2 = actualDamage(dmg2);
- cout << "Your HP: " << hp1 << endl;
- cout << enemyName << " HP: " << hp2 << endl;
- while (hp1 > 0 && hp2 > 0) { //fight
- if (turn == 1) {// player move
- cout << "\nType A to deal damage or type H to use potion" << endl;
- cin >> playerMove;
- if (playerMove == 'a' || playerMove == 'A') {
- turn--;
- hp2 = dealDamage(hp2, dmg1);
- cout << "Damage dealt: " << dmg1 << endl;
- cout << enemyName << " HP: " << hp2 << endl;
- }
- else if (playerMove == 'h' && healthPotion > 0 || playerMove == 'H' && healthPotion > 0) {
- turn--;
- healthPotion--;
- hp1 += randomNumber();// heals player (1, 50)
- cout << "\nYou drank potion and gained: " << randomNumber() << " HP " << endl;
- cout << "Potions remaining: " << healthPotion << endl;
- cout << "Your HP: " << hp1 << endl;
- }
- }
- else {// enemy move
- turn++;
- hp1 -= dmg2;
- hp2 += maxEnemyHealth * 0.06;//heals enemy by 6%
- cout << "\nDamage recieved: " << dmg2 << endl;
- cout << "Enemy regained " << (maxEnemyHealth * 0.06) << " HP " << endl;
- cout << enemyName << " HP: " << hp2 << endl;
- cout << "Your HP: " << hp1 << endl;
- cout << "____________________________________________________________" << endl; // end of the turn
- }
- }
- if (hp1 > 0 && hp2 < 0) {
- status = true;
- cout << "Player Wins" << endl;
- }
- else if (hp1 < 0 && hp2 < 0) {
- status = false;
- cout << "You both died" << endl;
- }
- else {
- status = false;
- cout << "You died!" << endl;
- }
- return status;//returns if player is alive
- }
- int dealDamage(int hp, int dmg) {// Dealing damage to entities
- hp -= dmg;
- return hp;
- }
- int actualDamage(int actualdmg) {//adds damage random's 10%(random is (1, 50))
- int(float(actualdmg += (randomNumber() * 0.10f)));
- return actualdmg;
- }
- int randomNumber() {// random (1, 50)
- int output;
- default_random_engine generator(time(NULL));
- uniform_int_distribution<int> interval(1, 50);
- output = interval(generator);
- return output;
- }
- /*int shopChoices(int gold) {
- int input;
- cout << "____________________________________________________________" << endl;
- cout << "Gold: " << gold << endl;
- cout << "Type 1 to buy Shield, cost: 100 Gold " << endl;
- cout << "Type 2 to buy Health Potion, cost: 35 Gold" << endl;
- cout << "Type 3 to upgrade sword (+10 Damage), cost: 200 Gold" << endl;
- cin >> input;
- return input;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment