Apparently, no so simple Math.....

Started by
12 comments, last by cavendert 9 years, 8 months ago

I see your min/max ops and raise you blocking logic!


int damageTaken = attack - defense;
if (damageTaken > 0)
    health -= damageTaken;
else
    Console.WriteLine("Attack blocked!");

In pokemon, all offensive attacks do at least one damage even if they should be 100% negated(except for move types that are uneffective against the opponent types(i.e ghost/normal iirc))

so, let me just fix chubu's real quick:

health -= max(attack - defense, 1)

All very nice! I do have one question. In this line of code right at the bottom, what is the 1 for? I get that we are trying to always do atleast 1 damage, but does that effect the code if normal damage is done?

Advertisement

I see your min/max ops and raise you blocking logic!


int damageTaken = attack - defense;
if (damageTaken > 0)
    health -= damageTaken;
else
    Console.WriteLine("Attack blocked!");

In pokemon, all offensive attacks do at least one damage even if they should be 100% negated(except for move types that are uneffective against the opponent types(i.e ghost/normal iirc))

so, let me just fix chubu's real quick:

health -= max(attack - defense, 1)

I was just about to say that. :)


Then make two?

If you find yourself saying that, consider making it a method of the class.


All very nice! I do have one question. In this line of code right at the bottom, what is the 1 for? I get that we are trying to always do atleast 1 damage, but does that effect the code if normal damage is done?


int x = max(attack - defense, 1);
is equivalent to

int x = attack - defense;
if (x < 1)
    x = 1;

Hello to all my stalkers.

Ah. That's what I was assuming, but I didn't want to assume. Thank you all for the advice!!!!

This topic is closed to new replies.

Advertisement