fix segmentation fault and revise file name
master
Sterben-01 2022-10-16 05:09:39 -05:00
parent 72d36140b3
commit 640e6ffde2
3 changed files with 9 additions and 11 deletions

View File

@ -19,7 +19,12 @@ GameAccount::GameAccount(string iName){
name = iName; name = iName;
setLevel(new Primary(this)); setLevel(new Primary(this));
} }
GameAccount::~GameAccount(){
if(level){
delete level;
level = nullptr;
}
}
void GameAccount::setLevel(Level* iLevel){ void GameAccount::setLevel(Level* iLevel){
if(level != nullptr){ if(level != nullptr){
delete level; delete level;
@ -48,6 +53,7 @@ void GameAccount::playCard(){
this->level->upgradeLevel(); this->level->upgradeLevel();
} }
void GameAccount::win(){ void GameAccount::win(){
if (this->getScore() < 200){ if (this->getScore() < 200){
setScore(getScore() + 50); setScore(getScore() + 50);

View File

@ -13,12 +13,7 @@ public:
GameAccount(string iName); GameAccount(string iName);
GameAccount(const GameAccount&) = delete; GameAccount(const GameAccount&) = delete;
GameAccount& operator=(const GameAccount&) = delete; GameAccount& operator=(const GameAccount&) = delete;
~GameAccount(){ ~GameAccount();
if(level){
delete level;
level = nullptr;
}
}
string getName(); string getName();
void win(); void win();
void lose(); void lose();

View File

@ -66,7 +66,6 @@ Secondary::Secondary(){
Secondary::Secondary(Level* level){ Secondary::Secondary(Level* level){
this->setGameAccount(level->getGameAccount()); this->setGameAccount(level->getGameAccount());
getGameAccount()->setLevel(level);
} }
void Secondary::doubleScore(){ void Secondary::doubleScore(){
@ -99,7 +98,6 @@ Professional::Professional(){
Professional::Professional(Level* level){ Professional::Professional(Level* level){
this->setGameAccount(level->getGameAccount()); this->setGameAccount(level->getGameAccount());
getGameAccount()->setLevel(level);
} }
void Professional::doubleScore(){ void Professional::doubleScore(){
@ -132,7 +130,6 @@ Final::Final(){
Final::Final(Level* level){ Final::Final(Level* level){
this->setGameAccount(level->getGameAccount()); this->setGameAccount(level->getGameAccount());
getGameAccount()->setLevel(level);
} }
void Final::doubleScore(){ void Final::doubleScore(){