Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include #include #include struct Item { enum class Type {sword, armor, shield, numTypes}; Type clasification; int bonusValue; }; struct Object {

#include 
#include  #include  #include  #include  #include  #include  struct Item { enum class Type {sword, armor, shield, numTypes}; Type clasification; int bonusValue; }; struct Object { enum class Type { player, slime, orc, sprite, dragon, numTypes }; Type name; int strength{ 0 }; int health{ 0 }; int level{ 0 }; std::map<:type item> inventory; }; std::vector createMonsters(const Object& player); void monsterAttack(Object& player, const std::vector& monsters); void bringOutYourDead(std::vector& monsters); void playerAttack(const Object& player, std::vector& monsters); void levelUp(Object& player); int calculateAC(const Object& object); void heal(Object& object); void displayBattle(const Object& player, const std::vector& monsters); void printName(const Object& object); void printItem(const Item & item); int attack(const Object& object); void defend(Object& object, int damage); std::random_device seed; std::default_random_engine engine(seed()); int main() { Object player{ Object::Type::player, 0,1,0, {} }; std::vector monsters; while (player.health > 0) { levelUp(player); monsters = createMonsters(player); std::cout  0 && monsters.size() > 0) { displayBattle(player, monsters); std::cout > command; switch (command) { case 'a': { playerAttack(player, monsters); break; } case 'h' : heal(player); break; default: std::cout & monsters) { printName(player); std::cout  createMonsters(const Object& player) { std::normal_distribution randomNumMonsters((double)player.level, player.level / 2.0); int numMonsters{ std::max(1, (int)randomNumMonsters(engine)) }; std::vector monsters; for (int i{ 0 }; i  monsterLevel((float)player.level, player.level / 4.0); int level{ std::max(1, (int)monsterLevel(engine)) }; std::uniform_int_distribution monsterType(1, (int)Object::Type::numTypes - 1); Object::Type name{ (Object::Type)monsterType(engine) }; double strengthVariance{ 0.0 }; double healthVariance{ 0.0 }; switch (name) { case Object::Type::slime: strengthVariance = level * 1.5; healthVariance = level * 1.25; break; case Object::Type::orc: strengthVariance = level * 2; healthVariance = level * level * 1.25; break; case Object::Type::sprite: strengthVariance = level * 1.75; healthVariance = level; break; case Object::Type::dragon: strengthVariance = level * 6; healthVariance = level * level * 3; break; } std::normal_distribution randomStrength(strengthVariance, level / 4.0); std::normal_distribution randomHealth(healthVariance * 5, level / 2.0); monsters.push_back( { name, std::max(1, (int)randomStrength(engine)), std::max(1, (int)randomHealth(engine)), level, {} }); } return monsters; } void monsterAttack(Object& player, const std::vector& monsters) { std::bernoulli_distribution willAttack(.75); std::cout & monsters) { std::cout > monsterNum; if (monsterNum > 0 && monsterNum  randomHealth(20.0 + player.level * 5, 5.0); player.health += std::max(1, (int)randomHealth(engine)); std::normal_distribution randomStrength(3.0 + player.level, 1.0); player.strength += std::max(1, (int)randomStrength(engine)); //grab new item. std::uniform_int_distribution randomItem(0, (int)Item::Type::numTypes - 1); std::normal_distribution randomBonus((double)player.level, (double)player.level / 2); Item found{ (Item::Type)randomItem(engine), std::max(1, (int)randomBonus(engine)) }; std::cout second.bonusValue; } if (auto shield{ object.inventory.find(Item::Type::shield) }; shield != object.inventory.end()) { AC += shield->second.bonusValue; } return AC; } void printName(const Object& object) { std::cout second.bonusValue; } std::normal_distribution damageDealt(potentialDamage, 2.0); printName(object); std::cout  defense(calculateAC(object), 1.0 / object.level); damage = std::max(0, damage - (int)defense(engine)); std::cout  randomHeal(object.strength, 3.0); int amountHealed{ std::max(1, (int)randomHeal(engine)) }; printName(object); std::cout & monsters) { for (auto monsterIter{ monsters.begin() }; monsterIter != monsters.end(); ) { if (monsterIter->health  
image text in transcribed
i am looking to switch out five loops within this code solution to an stl algorithm like the picture below asks
There are 5 for loops in my solution, we are going to switch the ones we can to STL algorithms. Fgrmy solution: 1. one used std::generate a. note::you have to create a vector with the right number of elements, b. std::vector v(4); would create a vector with 4 elements. 2. one used std::remove if 3. three used std: for_each NOTE: this is for practice. Most of these would be just fine as a ranged based for loop NOTE:: for the lambda parameter for player inventory. you will want to use: std: : pair

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

List four general control areas.

Answered: 1 week ago

Question

=+6. How does the writer establish credibility?

Answered: 1 week ago