0

My professor wants us to create a gladiator simulation where we name 5 gladiators, then create their stats, create the boss stats, then allow for the gladiators to fight the boss. During the fight, the health of everyone and randomly generated number damage dealt will be displayed until a winner is decided and from there, we will prompt the user if they would want a rematch.

Currently, I am stuck on figuring out what is and how do I use a constructor. Overall, I am lost with the project in total, but for now I want to understand this step by step. Inside the BossFight.h, consists of the prototype functions.

class BossFight {
private:
    //Holds the party of gladiators that is banded together to fight the boss
    Gladiator party[PSIZE];
    //Holds the powerful boss that the party is fighting
    Gladiator boss;
    //Variables used for record keeping
    int turnNum, fightsStarted, fightsWon;
    //Will fill the party with gladiators, this function can call/reuse the createGladiator function.
    void getParty();
    //Will generate a boss for the party to fight. Has no crit or evasion, but 3* damage min and range, and 6* health
    void getBoss();
    //Tells the user who won, after how many turns, and the current record for the session
    void displayFightResults(bool partyWon);
    //One turn occurs, where each party member attacks the boss, then the boss attacks the party.
    //Returned value indicates status of fight (continue, party win, party loss)
    //Boss will randomly choose between attacking a single (randomly chosen) party member for full damage, or
    //attacking the full party for half damage.
    int takeTurn();
    //Handles dealing damage to the entire party
    void bossAttacksArea();
public:
    //Responsible for generating the party and the boss, should initialize the other
    //private variables as well
    BossFight();
    //User calls this when they want to run a fight. It will ask them if they want to use
    //the same party, or get a new one.
    void runFight();
};

What I have done so far is

#include <iostream>
#include <string> 
#include "BossFight.h"
#include <stdlib.h> 
#include <time.h> // Allows seed to generate new random numbers every time.
using namespace std;

const int SIZE = 5; //Party Size


Gladiator createGladiator(string name) // Data type Gladiator with its data named createGladiator
{
    Gladiator stats; // Structure tag
    for (int i = 0; i < SIZE; i++)
    {
        int maxHealth, evasion, critical;
        stats.name = name;

        // set max health
        switch (rand() % 3) // % 3 means the range. So the starting number is 0 and final number is 2. Used to find a random number between the range 0-2. 
                            // Uses that random number to open up one of the cases. 
        {
        case 0: stats.maxHealth = 150;
            break;
        case 1: stats.maxHealth = 200;
            break;
        case 2: stats.maxHealth = 250;
            break;
        }
        // set evasion


        int numE = (rand() % 5);  // Used to find a random number between the range 0-4.
        switch (numE) // Uses that random number to open up one of the cases. 
        {
        case 0: stats.evasion = 50;
            break;
        case 1: stats.evasion = 75;
            break;
        case 2: stats.evasion = 100;
            break;
        case 3: stats.evasion = 125;
            break;
        case 4: stats.evasion = 150;
            break;
        }

        // Set Critical 

        int numC = (rand() % 5); // Used to find a random number  between the range 0-4.
        switch (numC) // // Uses that random number to open up one of the cases. 
        {
        case 0: stats.critical = 50;
            break;
        case 1: stats.critical = 75;
            break;
        case 2: stats.critical = 100;
            break;
        case 3: stats.critical = 125;
            break;
        case 4: stats.critical = 150;
            break;
        }

        // Set minDamage
        int minimum, maximum;
        minimum = 8;
        maximum = 5;
        int numMin = (minimum + rand() % (maximum + minimum)); // Used to find a random number between the minimum and maximum values.
        stats.dmgMin = numMin;

        // set DamageRange
        int maxMin, maxMax;
        maxMin = 16;
        maxMax = 5;
        int numMax = (maxMin + rand() % (maxMax - maxMin)); // Used to find a random number between the minimum and maximum values.
        stats.dmgRange = numMax;

        return stats; //Return all of the stats into the structure tag. 
    }
}


BossFight::BossFight() ***< -- stuck right here ***
{
    getParty();
}

void BossFight::getBoss()
{
    getBoss();
}
void getParty(string name[]) 
{

    {
        cout << "To begin with, enter 5 gladiator's name" << endl; // First for loop asking user for array input.
        for (int i = 0; i < SIZE; i++)
        {
            cin >> name[i];
        }
        for (int i = 0; i < SIZE; i++)
        {
            cout << "Gladiator " << i + 1 << " name is " << endl;
            cout << name[i] << endl;
        }
    }
}

int main()
{
    srand(time(NULL)); //initiate random number generator seed.

    string name[SIZE];
    cout << "Hello user" << endl;

    BossFight();

            system("PAUSE");
}

I would appreciate any type of help. Do remember that I am taking an intro to computer science class, so I may not understand complex coding yet. I have been doing fine so far interpreting how the code should work in english, but find it hard to interpret how it should be via code.

Also, I am getting an error

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "private: void __thiscall BossFight::getParty(void)" (?getParty@BossFight@@AAEXXZ) referenced in function "public: __thiscall BossFight::BossFight(void)" (??0BossFight@@QAE@XZ) ConsoleApplication6 Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "private: void __thiscall BossFight::getParty(void)" (?getParty@BossFight@@AAEXXZ) referenced in function "public: __thiscall BossFight::BossFight(void)" (??0BossFight@@QAE@XZ) ConsoleApplication6 C:\Users\1\documents\visual studio 2017\Projects\ConsoleApplication6\ConsoleApplication6\1.obj 1

And was wondering what even caused this? All i have in my visual studio is my header and cpp file.

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
Tony Do
  • 11
  • 4

1 Answers1

0

This is called a linker error. What the error is saying is that BossFight::getParty() is being used by the BossFight::BossFight() constructor implementation, but you haven't provided an implementation of the getParty() method.

It looks like you were trying to add an implementation by declaring and implementing a getParty(std::string*) function, but this is not an implementation of the BossFight::getParty() method.

To implement BossFight::getParty(), you will need something like:

void BossFight::getParty() {
  // implementation here
}

You will probably also want to hang on to the BossFight object that you construct by giving it a name:

BossFight boss_fight; // This declares *and* constructs a BossFight object on the stack.
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
  • Awesome! Thank you for your reply. I am still a bit lost as to what do you mean by implementation? I attempted doing void BossFight::getParty() { getParty; } and nothing happened. I assumed that's because I am calling a void function inside of a void function? – Tony Do May 08 '17 at 14:24
  • Hi @TonyDo: By "implementation" I mean the code that is executed when a function or method (also called "member function of a class") is called. Your `BossFight.h` header file contains some declarations and your CPP file contains some implementations. You need to write whatever code that should run when BossFight::getParty() is called within its implementation. You should implement (provide an implementation of) all of the BossFight methods. – Daniel Trebbien May 08 '17 at 15:20
  • As for your other question, it's fine to call a void function within a void function. But you probably don't want `void BossFight::getParty() { getParty(); }` because this would result in either an infinite loop or a stack overflow. – Daniel Trebbien May 08 '17 at 15:21