I just remade a program that uses a class for the user and a class for an enemy, I was testing the class system to see if I could make a good one. But it ended up not working. The compiler is complaining about "was expecting ; before "." operator practically everywhere I reference a function within a class.
Here is a sample, I lost the original in the depths of my flash drive, but this is as near as I can remember it:
everywhere I use player.anything or bob.anything it says it was expecting a ; before bob, '.', and anything. I think its complaining about me not having created the classes before I used them, but I'm not sure.Code:class zombie {
public:
zombie ( void ) {
hp = 100;
}
~zombie {}
void attack ( void ) {
//determines attack based on a random integer
//references player class's attack function
//returns the creatures attackpower to the player's takedamage function
}
void takedamage ( dmg ) {
//sets hp to a value based on defense and dmg taken
}
private:
int bite ( void ) {
//displays something for the user to see that the zombie attacked
//displays damage the zombie did
//returns attackpower
}
int gnaw ( void ) {
//does the same as above
}
int noattack ( void ) {
//displays something informing the user that the zombie failed to attack
//returns 0
}
int attackpower;
int attacktype; //to store the number that determines the attack the zombie will do
int hp;
};
class player {
//same as above, only with selectable attacks
public:
player ( void ) {
hp = 100;
}
~player {}
int attack ( void ) {
//allows player to select from a list of attacks, then uses that attack
//returns the attackpower of the attack chosen to the zombie's takedamage function
}
void takedamage ( dmg ) {
//sets hp to a value based on defense and dmg taken
}
private:
int axe ( void ) {
//displays text about what the attack did
//returns the attackpower
}
int shotgun ( void ) {
//does the same as above
}
int chainsaw ( void ) {
//does the same above
}
int attackpower;
int attacktype; //to store the number that determines the attack the zombie will do
int hp;
};
void battle ( void ) {
player player;
zombie bob;
while (player.hp > 0 and bob.hp > 0) {
if (bob.hp > 0) {
bob.attack();
}
if (player.hp > 0 ) {
player.attack();
}
}
if (player.hp <= 0) {
cout << "you lost";
exit (1);
}
if (bob.hp <= 0) {
cout << "you won";
}
}
int main() {
cout << //blablabla, set up scenario
battle ();
}