Files
wagic/projects/mtg/src/Player.cpp
wagic.the.homebrew@gmail.com d5be045859 Erwan
- Adding (dead) code for Story mode. This is FAR from being ready so it's deactivated in the code. I just don't want to create a branch (I'm lazy) and I'm fed up with synching. My Goal is to have a tutorial ready with this for the release after this one. If you want to test it (Note: the sample story is not interesting at ALL), just look for "Story mode" and uncomment (3 occurrences). PSP Or Linux need additions to the Makefile...
2010-02-16 10:55:03 +00:00

88 lines
2.1 KiB
C++

#include "../include/config.h"
#include "../include/Player.h"
#include "../include/GameObserver.h"
#include "../include/DeckStats.h"
#include "../include/ManaCost.h"
Player::Player(MTGPlayerCards * deck, string file, string fileSmall) : Damageable(20){
deckFile = file;
deckFileSmall = fileSmall;
game = deck;
game->setOwner(this);
manaPool = NEW ManaPool(this);
canPutLandsIntoPlay = 1;
mAvatar = NULL;
mAvatarTex = NULL;
type_as_damageable = DAMAGEABLE_PLAYER;
}
/*Method to call at the end of a game, before all objects involved in the game are destroyed */
void Player::End(){
DeckStats::GetInstance()->saveStats(this, opponent(),GameObserver::GetInstance());
}
Player::~Player(){
SAFE_DELETE(manaPool);
resources.Release(mAvatarTex);
mAvatar = NULL;
mAvatarTex = NULL;
}
const string Player::getDisplayName() const {
GameObserver * g = GameObserver::GetInstance();
if (this == g->players[0]) return "Player 1";
return "Player 2";
}
MTGInPlay * Player::inPlay(){
return game->inPlay;
}
int Player::getId(){
GameObserver * game = GameObserver::GetInstance();
for (int i= 0; i < 2; i++){
if (game->players[i] == this) return i;
}
return -1;
}
JQuad * Player::getIcon(){
return mAvatar;
}
Player * Player::opponent(){
GameObserver * game = GameObserver::GetInstance();
if (!game) return NULL;
return this == game->players[0] ? game->players[1] : game->players[0];
}
HumanPlayer::HumanPlayer(MTGPlayerCards * deck, string file, string fileSmall) : Player(deck, file, fileSmall) {
mAvatarTex = resources.RetrieveTexture("avatar.jpg",RETRIEVE_LOCK,TEXTURE_SUB_AVATAR);
if (mAvatarTex)
mAvatar = resources.RetrieveQuad("avatar.jpg",0,0,35,50,"playerAvatar",RETRIEVE_NORMAL,TEXTURE_SUB_AVATAR);
else
mAvatar = NULL;
}
ManaPool * Player::getManaPool(){
return manaPool;
}
int Player::afterDamage(){
return life;
}
//Cleanup phase at the end of a turn
void Player::cleanupPhase(){
game->inPlay->cleanupPhase();
game->graveyard->cleanupPhase();
}
ostream& operator<<(ostream& out, const Player& p)
{
return out << p.getDisplayName();
}