Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ programming; You have 3 monsters – each monster has a health (starts at 100)

ID: 3769610 • Letter: C

Question

C++ programming;

You have 3 monsters – each monster has a health (starts at 100) and a damage potential (starts as a random number between 1 and 3, multiplied by 2.) 2 monsters are randomly chosen to battle: subtract damage potential from the health of the monsters. Report score at the end of the battle. Write all information to a text file sorted by health. Battle again, choosing 2 monsters again. Example: Monster Health Damage Jabba the Hutt 100 2 Godzilla 100 4 Zombie 100 4 Battle 1: Output to screen - Jabba vs Godzilla – Godzilla Wins! Add to file: Zombie 100 Godzilla 98 Jabba the Hutt 96 ----- Battle 2: Output to screen - Zombie vs Godzilla – Tie! Add to file: Jabba the Hutt 96 Zombie 96 Godzilla 94 ----- After every 10 rounds (if there are 10 rounds) give the user the option to stop play. In battle, roll two 6-sided dice – the winner of the dice roll wins the battle and inflicts damage, the loser does NOT inflict damage. In the case of a tie, they roll again. The dice roll must be a function. The output must be modified as follows: Output to screen - Jabba vs Godzilla – Jabba rolls 4, Godzilla rolls 5. Godzilla Wins! Add to file: Zombie 100 Godzilla 100 Jabba the Hutt 96 ----- Output to screen - Zombie vs Godzilla – Zombie rolls 4, Godzilla rolls 4. A Tie! Roll again! Zombie rolls 1, Godzilla rolls 4 Add to file: Godzilla 100 Zombie 96 Jabba the Hutt 96

Explanation / Answer

Main.cpp

#include "MobClass.h"
#include "Player.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;
player battle(player account);
player calcEXP(player account,classMob monster);
player levelUp(player account);
void death();

int main()
{
    string name;
    int option1;
    cout << "Welcome, please enter your name ";
    cin >> name;
    string location[4] = {"in a hole","in a cave","in the mauntains","in a castle"};
    player account(name,location[0],1,0);
    cout <<" Welcome "<<account.getName() << " you find your self " << account.getArea() << " and you are not sure how you ended up here ";
    while (1)
    {
        Sleep(500);
        cout <<"write 1 to walk forward or 2 to walk left or 3 to walk right ";
        cin >> option1;
        if (option1 >=1 && option1 <=3)
        {
            Sleep(50*(option1));
            srand(time(NULL));
            if (rand() %3 == option1-1){
                account = battle(account);
            }

        }
        else{
            cout << " #@#Error#@# Please enter a number between 1 and 3 ";
            cin.clear();
            cin.ignore();
        }
    }
    return 0;

}


player battle(player account)
{
    string option;
    string location[4] = {"in a hole","in a cave","in the mauntains","in a castle"};
    string monsters[5][3] = {{"worm","lizard","snake"},{"rat","snake","trolls"},{"Dragon","Dragon","Dragon"},{"Evil knight","The mad king","Joffrey Baratheon"}};
    Sleep(20);
    srand(time(NULL));
    int ranM = (rand() % 3); //random monster
    int ranD = (rand() % 5)+1; //random diff
    classMob monster(monsters[account.getLevel()-1][ranM],account.getLevel(),account.getArea(),ranD);
    cout <<"Suddently you meet a "<< monster.getName() <<", be ready for battle" << " ";
    Sleep(2000);
    do
    {
        cout << " ###################################### HP:"<< account.getHealth() << "                                         "<< monster.getName()<<"HP:"<<monster.getHealth()<<" difficulty:"<<monster.getDifficulty() << " ";
        cout << "Write A for attack or R for retreat" << " ";
        cin >> option;
        srand(time(NULL));
        if (option == "R" || option == "r")
        {
            if ((rand() % 2) == 1){
                cout << "retreat sucessfull" << " ";
                monster.setHealth(0);
            }
            else{
                cout << "retreat failed, the monster get a free attack and you lose 5 health ";
                account.setHealth(account.getHealth()-5);
                option ="A";
            }
        }
        if (option == "A" || option == "a")
        {
            int attack =rand()%(account.getDamage());
            srand(time(NULL));
            int mobAttack = rand()%(monster.getDamage());
            monster.setHealth(monster.getHealth()-attack);
            account.setHealth(account.getHealth()-mobAttack);
            cout << "you attack the monster for " << attack << " damage ";
            Sleep(500);
            cout << "the monster counter attacks for " << mobAttack << " damage ";
            Sleep(500);
        }
    } while (monster.getHealth() >0 && account.getHealth() > 0);
    cout << " ###################################### HP:"<< account.getHealth() << "                                         "<< monster.getName()<<"HP:"<<monster.getHealth()<<" difficulty:"<<monster.getDifficulty() << " ";
    if (account.getHealth() <= 0)
    {
        death();
        exit(0);
    }
    account = calcEXP(account,monster);
    return account;
}

void death()
{
    cout << "Sorry you failed your epic quest ";
}

player calcEXP(player account,classMob monster)
{
    cout << "######### calculating EXP ######### ";
    Sleep(500);
    account.setEXP(account.getEXP() + monster.getEXP());
    cout << "EXP: " <<account.getEXP() << "/" << account.getEXPReq() << " ";
    if (account.getEXP() >= account.getEXPReq())
    {
        levelUp(account);
    }
    return account;
}

player levelUp(player account)
{
    account.setLevel(account.getLevel()+1);
    account.setEXPReq();
    account.setMaxHealth();
    account.setHealth(account.getMaxHealth());
    cout << "Level up! you are now level: " << account.getLevel() << "! ";
    return account;
}
Player.h

#include <string>
class player
{
public:
    player(std::string,std::string,int,int);
    void setName(std::string);
    void setArea(std::string);
    void setLevel(int);
    void setEXP(double);
    void setHealth(double);
    void setMaxHealth();
    void setDamage();
    std::string getName();
    std::string getArea();
    int getLevel();
    double getHealth();
    double getMaxHealth();
    int getDamage();
    int getEXP();
    void setEXP(int);
    int getEXPReq();
    void setEXPReq();
private:
    std::string playerName;
    std::string playerArea;
    int playerLevel;
    double playerHealth;
    double playerMaxHealth;
    int playerDamage;
    int EXP;
    int EXPReq;
};
player.cpp

#include <string>
#include "Player.h"
player::player(std::string name,std::string area,int level = 1,int EXP = 0)
{
    setName(name);
    setArea(area);
    setLevel(level);
    setEXP(EXP);
    setMaxHealth();
    setHealth(playerMaxHealth);
    setDamage();
    setEXPReq();
}

void player::setName(std::string name)
{
    playerName = name;
}
void player::setArea(std::string area)
{
    playerArea = area;
}
void player::setLevel(int level)
{
    playerLevel = level;
}
void player::setHealth(double health)
{
    playerHealth = health;
}
void player::setMaxHealth()
{
    playerMaxHealth = (100 * getLevel());
}
void player::setDamage()
{
    playerDamage = (30 * getLevel());
}

std::string player::getName()
{
    return playerName;
}

std::string player::getArea()
{
    return playerArea;
}

int player::getLevel()
{
    return playerLevel;
}
double player::getHealth()
{
    return playerHealth;
}
double player::getMaxHealth()
{
    return playerMaxHealth;
}
int player::getDamage()
{
    return playerDamage;
}

int player::getEXP()
{
    return EXP;
}
void player::setEXP(int _EXP)
{
    EXP = _EXP;
}
int player::getEXPReq()
{
    return EXPReq;
}
void player::setEXPReq()
{
    EXPReq = 70+((getLevel()*getLevel())*35);
}
mobclass.h

#include <string>

class classMob
{
public:
    classMob(std::string,int,std::string,int); // name,lvl,area,difficulty
    void setName(std::string);
    void setLevel(int);
    void setArea(std::string);
    void setDamage();
    void setHealth(double);
    void setMaxHealth();
    void setDifficulty(int);
    std::string getName();
    int getLevel();
    std::string getArea();
    int getDamage();
    double getHealth();
    double getMaxHealth();
    int getDifficulty();
    int getEXP();
    void setEXP();
private:
    std::string mobName;
    std::string mobArea;
    int mobLevel;
    int mobDamage;
    double mobHealth;
    double mobMaxHealth;
    int mobDifficulty;
    int EXP;
};
mobclass.cpp

#include <string>
#include "MobClass.h"
classMob::classMob(std::string name,int lvl,std::string area,int difficulty)
{
    setName(name);
    setLevel(lvl);
    setArea(area);
    setDifficulty(difficulty);
    setDamage();
    setMaxHealth();
    setHealth(mobMaxHealth);
    setEXP();
}

void classMob::setName(std::string name)
{
    mobName = name;
}

void classMob::setLevel(int level)
{
    mobLevel = level;
}

void classMob::setArea(std::string area)
{
    mobArea = area;
}

void classMob::setDifficulty(int difficulty)
{
    mobDifficulty = difficulty;
}

void classMob::setDamage()
{
    mobDamage = (3 *( getLevel())+((getDifficulty()*getLevel())/2));
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote