

#include <iostream>
#include <string>
using namespace std;

class Boss {
public:
  int hp, attackStrength, armor, magic;

  int bossAttack(int armor) {
    int dragonChoice = rand() % 4;
    int dmg = 0;
    if (dragonChoice == 0)
      dmg = attack(armor);
    else if (dragonChoice == 1)
      dmg = cast(armor);
    else
      cout << "BOSS says, \"I WILL DEFEAT YOU!\"" << endl;
    return dmg;
  }
  //the boss attacks physically!
  //this function returns dmg dealt
  int attack(int armor) {
    int dmg= rand() % 10 + attackStrength-armor;
    if (dmg < 0) dmg = 0;
    cout << "Boss Dealt: " << dmg << " damage " << endl;
    return dmg;
  }
  //the boss casts a spell
  //this function returns the damage dealt
  //by the spell
  int cast(int armor) {
    int dmg = rand() % 20 + magic - 10 - armor;
    if (dmg < 0) dmg = 0;
    cout << "Boss Casted! Dealt: " << dmg << " damage " << endl;
    return dmg;
  }
};

class Heroes {
public:
  int hp, attackStrength, armor, healing;

  int playerAttack(string choice, int armor) {
    int dmg = 0;
    if (choice == "attack")
      dmg = attack(armor);
    else if (choice == "heavy")
      dmg = heavyattack();
    else  //the choice was heal
      heal();
    return dmg;
  }


  //return dmg dealt by hero
  int attack(int armor) {
    int dmg = rand() % 10 + attackStrength;
    dmg = dmg - armor;
    if (dmg < 0) dmg = 0;
    cout << "Dealt: " << dmg << " damage" << endl;
    return dmg;
  }
  //heavy attack ignores armor 
  //but damages yourself
  int heavyattack() {
    int dmg = rand() % 20 + 3 * attackStrength;
    hp = hp - 5;
    cout << "Dealt: " << dmg << " damage" << endl;
    cout << "You over exert yourself" << endl;
    return dmg;
  }
  //modify the heroes health 
  //based on 1d10 + healing
  void heal() {
    hp = hp + healing + rand()%10;
    cout << "You feel healed!" << endl;
  }
};


string getChoice() {
  cout << "Choose: attack, heavy or heal? ";
  string moveChoice;
  cin >> moveChoice;
  while (moveChoice != "attack" && moveChoice != "heal" &&
	 moveChoice != "heavy") {
    cout << "Choose only attack, heavy or heal: ";
    cin >> moveChoice;
  }
  return moveChoice;
}

int main() {
  Boss dragon;//(1000, 10, 30, 30); w/ constructor
  dragon.hp = 1000;
  dragon.armor = 10;
  dragon.attackStrength = 30;
  dragon.magic = 30;
  Heroes knight;
  knight.hp = 100;
  knight.armor = 8;
  knight.attackStrength = 25;
  knight.healing = 10;

  while (knight.hp > 0 && dragon.hp > 0) {
    string choice = getChoice();
    dragon.hp -= knight.playerAttack(choice, dragon.armor);
    knight.hp -= dragon.bossAttack(knight.armor);
    cout << "Knight has " << knight.hp << endl;
    cout << "Dragon has " << dragon.hp << endl;
  }
  cout << "Knight has " << knight.hp << endl;
  cout << "Dragon has " << dragon.hp << endl;
}
