Skip to content

Commit

Permalink
handled lifetime of activities
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipagaxi committed Mar 20, 2024
1 parent 7704fa0 commit ae4b5c8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/include/Activities/Activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GameState;

class Activity {
public:
virtual ~Activity();
virtual void executeActivity(GameState &gameState);
};

Expand Down
1 change: 1 addition & 0 deletions src/include/Activities/FightActivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class FightActivity: public Activity {
public:
FightActivity(GameState &gameState);
~FightActivity();

void executeActivity(GameState &gameState) override;
void runFight(GameState &gameState);
Expand Down
4 changes: 2 additions & 2 deletions src/main/Activities/Activity.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Activities/Activity.hpp"


Activity::~Activity() {
}

void Activity::executeActivity(GameState &gameState) {
std::cout << "Activity is called" << std::endl;
}
7 changes: 6 additions & 1 deletion src/main/Activities/FightActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ FightActivity::FightActivity(GameState &gameState) : playerStatsBox(gameState, g
this->turnSP.setPosition((windowSize.x - turnStateSignSize.width) * 0.5 , -2.0);
}

FightActivity::~FightActivity() {
}

void FightActivity::runEnemiesTurn(GameState &gameState) {
if (!enemyDamageCalculated) {
this->turnIsChanging = false;
Expand Down Expand Up @@ -117,8 +120,8 @@ void FightActivity::executeActivity(GameState &gameState) {
this->exitButton.setPosition(windowSize.x * 0.99 - buttonSize.width, windowSize.x * 0.01);
this->runFight(gameState);

window->draw(this->backgroundSP);
window->draw(this->turnSP);
window->draw(this->backgroundSP);
this->playerOverview.draw(*window);
this->enemyOverview.draw(*window);
this->exitButton.draw(*gameState.gameWindow);
Expand All @@ -130,7 +133,9 @@ void FightActivity::executeActivity(GameState &gameState) {
if (this->exitButton.clickListener(gameState)) {
this->backgroundMusic.stop();
std::unique_ptr<MenuActivity> menu = std::make_unique<MenuActivity>(gameState);
//MenuActivity* menuActivity = new MenuActivity(gameState);
gameState.setCurrentActivity(std::move(menu));
//menu.release();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/Activities/MenuActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ MenuActivity::MenuActivity(GameState &gameState) {
}

MenuActivity::~MenuActivity() {
std::cout << "Menu Deconstructor called..." << std::endl;
}

void MenuActivity::executeActivity(GameState &gameState) {
Expand All @@ -44,6 +43,7 @@ void MenuActivity::executeActivity(GameState &gameState) {
this->backgroundMusic.stop();
std::unique_ptr<FightActivity> fight = std::make_unique<FightActivity>(gameState);
gameState.setCurrentActivity(std::move(fight));

}

if (buttonExit.clickListener(gameState)) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GameState::GameState(sf::RenderWindow &window, ActivityEnum activity) {

void GameState::setCurrentActivity(std::unique_ptr<Activity> newActivity) {
std::cout << "set activity called" << std::endl;
this->currentActivity.reset();
//this->currentActivity.release();
this->currentActivity = std::move(newActivity);
//this->currentActivity = newActivity;
}
3 changes: 3 additions & 0 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ int main()
//generateTexture();

std::unique_ptr<MenuActivity> menu = std::make_unique<MenuActivity>(gameState);
//menu.reset();
//MenuActivity* menuActivity = new MenuActivity(gameState);
gameState.setCurrentActivity(std::move(menu));
//menu.release();

//gameState.backgroundMusic.openFromFile(RESOURCE_PATH "music/menu_background_music.wav");
//gameState.backgroundMusic.setLoop(true);
Expand Down

0 comments on commit ae4b5c8

Please sign in to comment.