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:
@@ -73,6 +73,8 @@ public:
|
|||||||
void unTapPhase();
|
void unTapPhase();
|
||||||
MTGInPlay * inPlay();
|
MTGInPlay * inPlay();
|
||||||
ManaPool * getManaPool();
|
ManaPool * getManaPool();
|
||||||
|
void takeMulligan();
|
||||||
|
|
||||||
void cleanupPhase();
|
void cleanupPhase();
|
||||||
virtual int Act(float dt)
|
virtual int Act(float dt)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ void GameStateDuel::Start()
|
|||||||
if (nbDecks)
|
if (nbDecks)
|
||||||
{
|
{
|
||||||
decksneeded = 0;
|
decksneeded = 0;
|
||||||
if (nbDecks > 1) deckmenu->Add(MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck.");
|
deckmenu->Add(MENUITEM_RANDOM_PLAYER, "Random", "Play with a random deck.");
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDeckMenu(deckmenu, playerDeckList);
|
renderDeckMenu(deckmenu, playerDeckList);
|
||||||
@@ -776,19 +776,8 @@ void GameStateDuel::ButtonPressed(int controllerId, int controlId)
|
|||||||
break;
|
break;
|
||||||
case MENUITEM_MULLIGAN:
|
case MENUITEM_MULLIGAN:
|
||||||
//almosthumane - mulligan
|
//almosthumane - mulligan
|
||||||
|
game->currentPlayer->takeMulligan();
|
||||||
|
|
||||||
|
|
||||||
int cardsinhand = game->players[0]->game->hand->nb_cards;
|
|
||||||
|
|
||||||
for (int i = 0; i < cardsinhand; i++) //Discard hand
|
|
||||||
game->currentPlayer->game->putInZone(game->currentPlayer->game->hand->cards[0],
|
|
||||||
game->currentPlayer->game->hand,
|
|
||||||
game->currentPlayer->game->library);
|
|
||||||
|
|
||||||
game->currentPlayer->game->library->shuffle(); //Shuffle
|
|
||||||
|
|
||||||
for (int i = 0; i < (cardsinhand - 1); i++)
|
|
||||||
game->draw(); //Draw hand with 1 less card penalty //almhum
|
|
||||||
menu->Close();
|
menu->Close();
|
||||||
mGamePhase = DUEL_STATE_CANCEL;
|
mGamePhase = DUEL_STATE_CANCEL;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -173,6 +173,23 @@ int Player::prevented()
|
|||||||
{
|
{
|
||||||
return preventable;
|
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
|
//Cleanup phase at the end of a turn
|
||||||
void Player::cleanupPhase()
|
void Player::cleanupPhase()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user