I didn’t know how to summarize this in the title, but I want to create the most basic of class based rogelikes and since I want different characters to have different attacks(not just lowering enemy health) I decided to make the attack functions be methods of classes and then based on user input make a static hero
object. But if I define hero
inside a switch
and have each case
be a different definition of hero
it counts it as multiple definitions of hero
within one scope(but in reality it will get defined once because that’s how switch
works). Is there any other non-if else
-y way to have different functions for attacks as opposed to having them as methods.(here’s the .h file where the classes are defined).
Note: I know basically nothing about c++. It’s totally possible im barking up the wrong tree and I shouldn’t bother with classes, but i can only think of the if else approach and some tags for which hero functions to call.
class HERO {
public:
int hp, hp_max;
int dmg, def;
int speed, luck, time;
};
class Guyone : HERO {
public:
Guyone() {
hp = 100;
hp_max = 100;
dmg = 15;
def = 10;
speed = 50;
luck = 3;
time = 0;
}
//IMPORTANT PART
void attack_a(int* m_hp, int* m_def, int* dmg) {
return;
}
void attack_b(int* m_hp, int* m_def, int* dmg) {
return;
}
void action(int* m_hp, int* m_def, int* h_dmg) {
cout << "whatcha gonna do";
switch (getchar()) {
case 'a':
attack_a(m_hp, m_def, h_dmg);
}
}
};
class Guytwo : HERO {
public:
Guytwo() {
hp = 100;
hp_max = 100;
dmg = 15;
def = 10;
speed = 50;
luck = 3;
time = 0;
}
//method with the same name, so it can do different things
//if i need it to, say make the bad guy armor go down
void attack_a(int* m_hp, int* m_def, int* dmg) {
return;
}
void attack_b(int* m_hp, int* m_def, int* dmg) {
return;
}
void action(int* m_hp, int* m_def, int* h_dmg) {
cout << "whatcha gonna do";
switch (getchar()) {
case 'a':
attack_a(m_hp, m_def, h_dmg);
}
}
};