- moved all "loseLife/gainLife" duplicated code into 1 Player method
This commit is contained in:
wagic.the.homebrew@gmail.com
2011-01-23 06:59:00 +00:00
parent 14f2e9b0f2
commit f63aa379e7
9 changed files with 88 additions and 92 deletions
+39
View File
@@ -116,6 +116,45 @@ ManaPool * Player::getManaPool()
return manaPool;
}
int Player::gainOrLoseLife(int value)
{
if (!value)
return 0; //Don't do anything if there's no actual life change
thatmuch = abs(value); //What is thatmuch used for?
life+=value;
if (value<0)
lifeLostThisTurn -= value;
//Send life event to listeners
WEvent * lifed = NEW WEventLife(this,value);
GameObserver * game = GameObserver::GetInstance();
game->receiveEvent(lifed);
return value;
};
int Player::gainLife(int value)
{
if (value <0)
{
DebugTrace("PLAYER.CPP: don't call gainLife on a negative value, use loseLife instead");
return 0;
}
return gainOrLoseLife(value);
};
int Player::loseLife(int value)
{
if (value <0)
{
DebugTrace("PLAYER.CPP: don't call loseLife on a negative value, use gainLife instead");
return 0;
}
return gainOrLoseLife(-value);
};
int Player::afterDamage()
{
return life;