I''ve been messing around with a simple text based battle system on the console (hopefully I can edit it to work when I get D3D working) for an RPG and I''ve been having trouble with the !(not) operator.
I have a member function of the player class to process the commands (Defend, Attack Power 1/3, 1/2, 1, and soon to be magic), and when the player chooses to defend it''s supposed to set Dmg (the damage variable) to 0. If I don''t do that it says that I hit the enemy (in this case peasant) for -899389 points, which gives him an absurd amount of HP.
Here''s the relavant code:
//player attack function
Player::Attack {
.
.
.
.
switch (Commands) {
case (com_Defend):
player.Defend = true;
cout << "You defend";
Dmg = 0;
break;
.
.
.
//*******************
//Main function
.
.
.
Dmg - player.Attack();
if (Dmg = 0 && !player.Defend) {
cout << "You missed\n";
}
.
.
.
The problem is when I defend I get "You defend" "You missed". It seems to be ignoring the not operator, and I''ve tried putting !player.Defend in parentheses.
I''ve also tried nested if statements:
if (Dmg = 0) {
if (!player.Defend) { //also tried if !(player.Defend)
cout << "You missed";
}
which yielded the same results.
By the way, I''m sorry if this has been addressed before, but my search turned up nothing.
300In the land of the proud and freeyou can sell your soul and your dignityfor fifteen minutes on tvhere in Babylon.