1) When "Cancel" from the 2nd deck selection was introduced, proper clean up was not implemented of the player information.

It was only handled at the end of the game or when somebody quit in the middle of a game.
    Nothing was done if somebody wanted to choose a differnet Player deck.
2) making clean up of objects a little more explicit in the mtggamezone and GameStateDuel objects
This commit is contained in:
techdragon.nguyen@gmail.com
2010-11-10 00:56:30 +00:00
parent f176f7378d
commit 2c3e1b551b
2 changed files with 16 additions and 7 deletions
+12 -6
View File
@@ -164,7 +164,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
deck[playerId] = mPlayers[playerId]->game; deck[playerId] = mPlayers[playerId]->game;
} }
} }
else { //Random AI deck else { //Random deck
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
Player * opponent = NULL; Player * opponent = NULL;
if (playerId == 1) opponent = mPlayers[0]; if (playerId == 1) opponent = mPlayers[0];
@@ -203,9 +203,14 @@ void GameStateDuel::End()
DebugTrace("Ending GameStateDuel"); DebugTrace("Ending GameStateDuel");
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
if (mPlayers[0] && mPlayers[1]) mPlayers[0]->End();
GameObserver::EndInstance();
DeckManager::EndInstance(); DeckManager::EndInstance();
if (mPlayers[0] && mPlayers[1]) // save the stats for the game
mPlayers[0]->End();
else // clean up player object
SAFE_DELETE( mPlayers[0] );
GameObserver::EndInstance();
game = NULL; game = NULL;
premadeDeck = false; premadeDeck = false;
@@ -258,7 +263,7 @@ void GameStateDuel::Update(float dt)
{ {
case DUEL_STATE_ERROR_NO_DECK: case DUEL_STATE_ERROR_NO_DECK:
if (JGE_BTN_OK == mEngine->ReadButton()) if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_DECK_VIEWER); mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break; break;
case DUEL_STATE_CHOOSE_DECK1: case DUEL_STATE_CHOOSE_DECK1:
if (mParent->gameType == GAME_TYPE_MOMIR){ if (mParent->gameType == GAME_TYPE_MOMIR){
@@ -309,7 +314,8 @@ void GameStateDuel::Update(float dt)
if (mParent->players[0] == PLAYER_TYPE_HUMAN){ if (mParent->players[0] == PLAYER_TYPE_HUMAN){
ensureOpponentMenu(); ensureOpponentMenu();
opponentMenu->Update(dt); opponentMenu->Update(dt);
}else{ }
else{
loadPlayer(1); loadPlayer(1);
mGamePhase = DUEL_STATE_PLAY; mGamePhase = DUEL_STATE_PLAY;
} }
@@ -425,7 +431,7 @@ void GameStateDuel::Update(float dt)
break; break;
default: default:
if (JGE_BTN_OK == mEngine->ReadButton()) if (JGE_BTN_OK == mEngine->ReadButton())
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
} }
} }
+4 -1
View File
@@ -353,8 +353,11 @@ MTGGameZone::MTGGameZone() : nb_cards(0), lastCardDrawn(NULL), needShuffle(false
MTGGameZone::~MTGGameZone(){ MTGGameZone::~MTGGameZone(){
for (int i=0; i<nb_cards; i++) { for (int i=0; i<nb_cards; i++) {
delete cards[i]; SAFE_DELETE( cards[i] );
} }
cards.clear();
cardsMap.clear();
owner = NULL;
} }
void MTGGameZone::setOwner(Player * player){ void MTGGameZone::setOwner(Player * player){