From 640e6ffde235d8d7ea18709dc4ca1c1e547eb8b5 Mon Sep 17 00:00:00 2001 From: Sterben-01 Date: Sun, 16 Oct 2022 05:09:39 -0500 Subject: [PATCH] fix bug fix segmentation fault and revise file name --- .../2.Code/{GameAccout.cpp => GameAccount.cpp} | 8 +++++++- 21.StatePattern/2.Code/GameAccount.h | 9 ++------- 21.StatePattern/2.Code/Level.cpp | 3 --- 3 files changed, 9 insertions(+), 11 deletions(-) rename 21.StatePattern/2.Code/{GameAccout.cpp => GameAccount.cpp} (93%) diff --git a/21.StatePattern/2.Code/GameAccout.cpp b/21.StatePattern/2.Code/GameAccount.cpp similarity index 93% rename from 21.StatePattern/2.Code/GameAccout.cpp rename to 21.StatePattern/2.Code/GameAccount.cpp index 439666f..a5edd94 100644 --- a/21.StatePattern/2.Code/GameAccout.cpp +++ b/21.StatePattern/2.Code/GameAccount.cpp @@ -19,7 +19,12 @@ GameAccount::GameAccount(string iName){ name = iName; setLevel(new Primary(this)); } - +GameAccount::~GameAccount(){ + if(level){ + delete level; + level = nullptr; + } +} void GameAccount::setLevel(Level* iLevel){ if(level != nullptr){ delete level; @@ -48,6 +53,7 @@ void GameAccount::playCard(){ this->level->upgradeLevel(); } + void GameAccount::win(){ if (this->getScore() < 200){ setScore(getScore() + 50); diff --git a/21.StatePattern/2.Code/GameAccount.h b/21.StatePattern/2.Code/GameAccount.h index b2283f4..b974a4a 100644 --- a/21.StatePattern/2.Code/GameAccount.h +++ b/21.StatePattern/2.Code/GameAccount.h @@ -13,12 +13,7 @@ public: GameAccount(string iName); GameAccount(const GameAccount&) = delete; GameAccount& operator=(const GameAccount&) = delete; - ~GameAccount(){ - if(level){ - delete level; - level = nullptr; - } - } + ~GameAccount(); string getName(); void win(); void lose(); @@ -33,4 +28,4 @@ private: string name; }; -#endif +#endif \ No newline at end of file diff --git a/21.StatePattern/2.Code/Level.cpp b/21.StatePattern/2.Code/Level.cpp index 4594f88..e77bb1a 100644 --- a/21.StatePattern/2.Code/Level.cpp +++ b/21.StatePattern/2.Code/Level.cpp @@ -66,7 +66,6 @@ Secondary::Secondary(){ Secondary::Secondary(Level* level){ this->setGameAccount(level->getGameAccount()); - getGameAccount()->setLevel(level); } void Secondary::doubleScore(){ @@ -99,7 +98,6 @@ Professional::Professional(){ Professional::Professional(Level* level){ this->setGameAccount(level->getGameAccount()); - getGameAccount()->setLevel(level); } void Professional::doubleScore(){ @@ -132,7 +130,6 @@ Final::Final(){ Final::Final(Level* level){ this->setGameAccount(level->getGameAccount()); - getGameAccount()->setLevel(level); } void Final::doubleScore(){