creating a change in a enum in c++

I am creating a game when the player lands on "F", the enumeration in the player class has to change between good and bad.

For example, if the player already has good and lands on "F", it will change to bad, and if players lands back on 'F' it will be good again and so on.

player.h

class Player {
public:
int health = 100;
int weapon = 1;
int lvl = 0;

Player(bool hero) {
if (hero) {
health;
weapon;
} else {
health = 1;
}
}

enum Alignment { good, bad };

void attack(Enemy &e);

friend class Enemy;
};
main.cpp

if (gameBoard[positionX][positionY] == gameBoard[0][4]) {
cout << "\nWell Of Reflection\n" << endl;
cout << "You increases your XP by 2" << endl;
p.lvl += 2;
cout << "Total XP: " << p.lvl << endl;
Alignment = // HERE
}
You already have a Player class, add a member data that encapsulates the alignment.

I personally wouldn't create an enum for just two possibilities, I'd use a bool. Using the NOT operator(!) to toggle the change.

I'd use the conditional (ternary) operator to provide a string of "good" or "bad" as needed.
https://www.cplusplus.com/articles/1AUq5Di1/

PLEASE learn to use code tags, they make reading/commenting on source code MUCH easier.
http://www.cplusplus.com/articles/jEywvCM9/

HINT: you can edit your post and add code tags.
Topic archived. No new replies allowed.