enum Alignment { good, bad };
Declares a type called Alignment
, not a variable. Your line
Alignment = // HERE
would attempt to assign a value to a type, which makes no sense.
You'd need something like this:
enum Alignment { good, bad };
Alignment myAlignment = good;
I really prefer to use scoped enums like this:
enum class Alignment { good, bad };
Aligmnent myAlignment = Alignment::good;
They're functionally equivalent, but the latter gives the compiler some hints that can catch coding errors at compile time.
On a side note: note that in your post, the word Alignment
is displayed in that blue/green color reserved for types.
Applying this to your class definition:
class Player {
public:
int health = 100;
int weapon = 1;
int lvl = 0;
Player(bool hero) {
if (hero) {
// health; THESE LINES DO NOTHING BUT GENERATE A WARNING.
// weapon;
} else {
health = 1;
}
}
// Alignment is a nested type that can be referred to as Player::Alignment.
enum class Alignment { good, bad };
Alignment playerAlignment = Alignment::good;
void attack(Enemy &e);
friend class Enemy;
};
And later on...
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;
p.playerAlignment = Player::Alignment::bad;
}
Or if you want to display the player's alignment:
std::string to_string(Player::Alignment alignment)
{
switch(alignment)
{
case Player::Alignment::good:
return "good";
case Player::Alignment::bad:
return "bad";
}
return "Unknown alignment";
}
And elsewhere when you want to use that:
cout << "Alignment: " << to_string(p.playerAlignment) << endl;