Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <tuple>
- #include <ctime>
- using namespace std;
- int DealDamage(int, int);
- int ActualDamage(int);
- int RandomNumber();
- int Shop(int&, int&);
- int IsPlayerAlive(int&);
- void Stage1(int&);
- int Fight(int& , int, int, int, string, int&);
- int main() {
- bool playerIsAlive;
- int gold = 0;
- int skillPoints = 0;
- int healthPotions = 3;
- int playerHealth = 100;
- int playerDamage = 25;
- int wolfHealth = 100;
- int wolfDamage = 15;
- //Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, "Wolf", healthPotions);
- //Stage1(playerHealth);
- if (Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, "Wolf", healthPotions) == true) {
- gold += 100;
- skillPoints += 1;
- cout << "____________________________________________________________" << endl;
- cout << "Well Done, you gained " << gold << " Gold " << endl;
- cout << "Your HP: " << playerHealth << endl;
- Shop(gold, healthPotions);
- cout << gold << " " << healthPotions << endl;
- }
- else {
- cout << "Baah NOOB!" << endl;
- }
- }
- 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)
- default_random_engine generator(time(NULL));
- uniform_int_distribution<int> interval(1, 50);
- return interval(generator);
- }
- int IsPlayerAlive(int& playerHealth){
- if (playerHealth > 0) {
- return true;
- }
- else {
- return false;
- }
- }
- void Stage1(int& playerHealth) {
- if (IsPlayerAlive(playerHealth)) {
- cout << "You are alive" << endl;
- }
- else {
- cout << "You Died" << endl;
- }
- }
- int Shop(int& gold,int& healthPotions) {
- int input = 0;
- 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;
- cout << "Type B to leave the shop" << endl;
- cin >> input;
- if (input == 1 && gold >= 100) {
- gold -= 100;
- cout << "You now have a Shield \nGold Remaining: " << gold << endl;
- }
- else if (input == 2 && gold >= 35) {
- gold -= 35;
- healthPotions++;
- cout << "You purchased health potion \nGold Remaining: " << gold << endl;
- }
- else if (input == 3 && gold >= 200) {
- gold -= 200;
- cout << "You upgraded Sword \nGold Remaining: " << gold << endl;
- }
- else if (input == 'b' || input == 'B') {
- return 0;
- }
- return 0;
- }
- int Fight(int& playehp, int hp2, int dmg1, int dmg2, 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: " << playehp << endl;
- cout << enemyName << " HP: " << hp2 << endl;
- while (playehp > 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--;
- playehp += RandomNumber();// heals player (1, 50)
- cout << "\nYou drank potion and gained: " << RandomNumber() << " HP " << endl;
- cout << "Potions remaining: " << healthPotion << endl;
- cout << "Your HP: " << playehp << endl;
- }
- }
- else {// enemy move
- turn++;
- playehp -= 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: " << playehp << endl;
- cout << "____________________________________________________________" << endl; // end of the turn
- }
- }
- /*if (playehp > 0 && hp2 < 0) {
- status = true;
- cout << "Player Wins" << endl;
- }
- else if (playehp < 0 && hp2 < 0) {
- status = false;
- cout << "You both died" << endl;
- }
- else {
- status = false;
- cout << "You died!" << endl;
- }
- return status;//returns if player is alive*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment