moved mulligan code out of GameStateDuel and into Player base class. Taking a mulligan seems better

encapsulated as a player function rather than loose code inside the state transitions of GameStateDuel

Note: Inside of the mulligan code I assigned game to currentPlayerZones for clarification rather than
something functionally required.  "game" seems ambiguous as "game" is also referenced throughout the code for the GameObserver
keeping this change localized to this method until more analysis can be done.  The pattern that was here before was
game->currentPlayer->game
where the first "game" represented the GameObserver and the second the collection of zones (MTPPlayerCards) to the current player.
I would suggest changing the Player instance of game to something that represents its data, the game zones associated to the current player.
"game" seems too generic, as it can be interpreted to encompass many things rather than just dealing with the different zones (library, exile, discard, etc )
This commit is contained in:
techdragon.nguyen@gmail.com
2011-01-28 13:30:29 +00:00
parent 3187487987
commit 5e651f03b2
3 changed files with 110 additions and 102 deletions

View File

@@ -136,25 +136,25 @@ int Player::gainOrLoseLife(int value)
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::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()
@@ -173,6 +173,23 @@ int Player::prevented()
{
return preventable;
}
void Player::takeMulligan()
{
MTGPlayerCards * currentPlayerZones = game;
int cardsinhand = currentPlayerZones->hand->nb_cards;
for (int i = 0; i < cardsinhand; i++) //Discard hand
currentPlayerZones->putInZone(currentPlayerZones->hand->cards[0],
currentPlayerZones->hand,
currentPlayerZones->library);
currentPlayerZones->library->shuffle(); //Shuffle
for (int i = 0; i < (cardsinhand - 1); i++)
game->drawFromLibrary();
//Draw hand with 1 less card penalty //almhum
}
//Cleanup phase at the end of a turn
void Player::cleanupPhase()
{