Canceling the addition

At the part of counting the damage done by the monster towards the player. Is it possible to have the player take no damage instead of the HP increasing because (-) (-) = (+).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
do
     {
     
     cout<<"Enemy HP : "<<enemyHP;
     cout<<"\t\t\t\tYour HP : "<<player.pHealth<<endl;
     
     cout<<"1. Attack It!"<<endl;
     cout<<"2. Run!!!!"<<endl<<endl;
     
     cout<<"Your Choice : ";
     cin>>choice;
     
     
     if (choice == 1)
     {
                enemyHP -= player.pAtkPoint;               
                
                if(enemyHP > 0)
                {
                           player.pHealth = player.pHealth - (enemyATK-player.pDefPoint);
                }              
     }
     
     else if (choice == 2)
     {
          player.pPosX = player.pOldPosX;
          player.pPosY = player.pOldPosY;
     }    
    
     cout<<string(50,'\n');
     }
     while((enemyHP > 0) && (player.pHealth > 0));
make a variable, maxhealth,
set phealth to maxhealth
 
int maxhealth=preferred max health

and
pHealth=maxhealth

maybe?
im new to coding... im not even sure if thats what you wanted
Last edited on
dont understand what you want to do there.
but with that sourcecode you get healed, if your defense is bigger than the monsters damage

if thats the problem, just add another if statement before line 20 and check if def > ATK. if thats the case just dont do any changes to the health
Last edited on

Darkmaster (215) Dec 5, 2012 at 9:12pm
dont understand what you want to do there.
but with that sourcecode you get healed, if your defense is bigger than the monsters damage

if thats the problem, just add another if statement before line 20 and check if def > ATK. if thats the case just dont do any changes to the health


yeayea u got what i wanted , was just wondering if there is another way to go around it without another IF statement
Topic archived. No new replies allowed.