#include #include #include //Used for random number generator using namespace std; class character { private: //These will only be able to be accessed within the class string name; //Set a name for the character int level; //Character level - nothing set in stone at the moment - may set a limiter int health; //When goes to 0 then character dies int attack; //This make character strong int defense; //This makes the character a tank int agility; //This makes the character go burrrr int spirit; //Use the force public: //This section used to set the values for later - game abbreviations for simplicity character(string n, int lvl, int hp, int atk, int def, int agi, int spr) : name(n), level(lvl), health(hp), attack(atk), defense(def), agility(agi), spirit(spr) {} string getName() const { return name; } //Gets name errors later without this since name was private //It didn't make sense to use the pointers for this part like how I did in the structure homework void stats() const { cout << name << "\n"; cout << "Level: " << level << "\n"; cout << "Health: " << health << "\n"; cout << "Attack: " << attack << "\n"; cout << "Defense:" << defense << "\n"; cout << "Agility:" << agility << "\n"; cout << "Spirit: " << spirit << "\n"; } //Makes another character type for battle purposes using "&" to get the address void attackEnemy(character &defender) { int damage = (attack - defender.defense /2) + (rand() % 50); //Random extra damage for variety if (damage < 0) damage = 0; //Makes no negative damage defender.health -= damage; if (defender.health < 0) defender.health = 0; //Makes no negative health cout << name << " attacks " << defender.name << " for " << damage << " damage!\n"; cout << defender.name << " now has " << defender.health << " health left.\n"; } //To keep track of when battle is over bool isAlive() const { return health > 0; } }; int main() { srand(time(0)); character hero("CompSci Legend", 100, 9999, 999, 999, 999, 999); //Fake max stats for player character enemy("Fordham ExamX", 100, 25000, 700, 930, 999, 999); //Boss health always over max cout << "HERO STATS\n"; hero.stats(); cout << "\nENEMY STATS\n"; enemy.stats(); //Battle stuff cout << "\nC's gets degrees - FIGHT!\n\n"; //To ensure stat information can be ready before the battle stuff cout << "press - enter - key to begin the battle\n"; cin.get(); hero.attackEnemy(enemy); enemy.attackEnemy(hero); //Fight till someone wins while (hero.isAlive() && enemy.isAlive()) { hero.attackEnemy(enemy); if (!enemy.isAlive()) { cout << "\n" << enemy.getName() << " has been defeated! " << hero.getName() << " passes this semester!\n"; break; } enemy.attackEnemy(hero); if (!hero.isAlive()) { cout << "\n" << hero.getName() << " has been defeated! " << enemy.getName() << " recommends tutoring!\n"; break; } } return EXIT_SUCCESS; }