Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete this using C++. You have two files, mob.cpp and main.cpp mob.cpp is an implementation file containing the implementation of Mob class. It contains the

Complete this using C++. You have two files, mob.cpp and main.cpp

mob.cpp is an implementation file containing the implementation of Mob class. It contains the following code:

#include "mob.h" #include #include

Mob::Mob(std::string name) : Mob() { this->name= name; stat_construct(); }

Mob::Mob() { stat_construct(); }

void Mob::stat_construct() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> disBig(10, 20); std::uniform_real_distribution<> disSmall(1, 5);

currentHP= maxHP= disBig(gen); currentMP= maxMP= disBig(gen); str = disSmall(gen); con = disSmall(gen); dex = disSmall(gen); agi = disSmall(gen); mnd = disSmall(gen); wis = disSmall(gen);

currentStamina= maxStamina= 2 * (con + str); }

void Mob::weak_attack(Mob *target) { if(currentStamina < mainHand.weight) { std::cout << name << " is too tired to swing. "; return; } float damage= mainHand.baseDamage + mainHand.strengthScaling * str; this->currentStamina-= mainHand.weight; std::cout << this->name << " swung " << mainHand.name << ". "; target->take_damage(damage); }

void Mob::strong_attack(Mob *target) { if(currentStamina < mainHand.weight * 2) { std::cout << name << " is too tired to swing hard! "; return; } float damage= mainHand.baseDamage + mainHand.strengthScaling * str * 1.5; this->currentStamina-= mainHand.weight * 2; std::cout << this->name << " swung " << mainHand.name << " hard! "; target->take_damage(damage); }

void Mob::regen() { currentHP+= 1; if(currentHP > maxHP) currentHP= maxHP; currentStamina+= 1; if(currentStamina > maxStamina) currentStamina= maxStamina; }

void Mob::pick_weapon(Weapon w) { mainHand= w; }

int Mob::take_damage(int d) { currentHP-= d; std::cout << this->name << " took " << d << " damage! "; return d; }

main.cpp contains a small program using Mob objects, and contains the following code:

#include "mob.h" #include #include #include using namespace std;

int main() { srand(time(nullptr)); Mob stronk("Stronk"); Mob heWhoseNameIsNotSetViaConstructor; heWhoseNameIsNotSetViaConstructor.set_name("Tim"); /* {name, baseDamage, strengthScaling, weight} */ Weapon club = {"Stronk's big stick", 2, 0.8, 3}; Weapon sword= {"Oakeshott", 5, 0.2, 3};

stronk.pick_weapon(club); heWhoseNameIsNotSetViaConstructor.pick_weapon(sword);

while(stronk.get_hp() > 0 && heWhoseNameIsNotSetViaConstructor.get_hp() > 0) { cout << "Stronk: " << stronk.get_hp() << "/" << stronk.get_stamina() << " "; cout << "Tim: " << heWhoseNameIsNotSetViaConstructor.get_hp() << "/" << heWhoseNameIsNotSetViaConstructor.get_stamina() << " "; int r= rand() % 2; switch(r) { case 0: stronk.weak_attack(&heWhoseNameIsNotSetViaConstructor); break; case 1: stronk.strong_attack(&heWhoseNameIsNotSetViaConstructor); } r= rand() % 2; switch(r) { case 0: heWhoseNameIsNotSetViaConstructor.weak_attack(&stronk); break; case 1: heWhoseNameIsNotSetViaConstructor.strong_attack(&stronk); } cout << " "; this_thread::sleep_for(chrono::seconds(2)); stronk.regen(); heWhoseNameIsNotSetViaConstructor.regen(); }

cout << "End result: Stronk: " << stronk.get_hp() << " hp Tim: " << heWhoseNameIsNotSetViaConstructor.get_hp() << endl;

return 0; }

Write the class header in mob.h to match the functions implemented in mob.cpp and test the class with the given main.cpp. You must also complete the inline getter/setter functions in the Mob class that are not implemented in mob.cpp. These are references in the main(). Please include comments wherever you can!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago