From 0bc65f2ffdba2c8ab8f7650db45fbe30d6503403 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:42:56 +0200 Subject: [PATCH] when there is only one player remaing, goes back --- CMakeLists.txt | 2 ++ .../EndCondition/EndConditionSystem.cpp | 21 +++++++++++++++ .../EndCondition/EndConditionSystem.hpp | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 sources/System/EndCondition/EndConditionSystem.cpp create mode 100644 sources/System/EndCondition/EndConditionSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b561e9..106dedef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,8 @@ set(SOURCES sources/Runner/CreditScene.cpp sources/Component/Score/ScoreComponent.cpp sources/Component/Score/ScoreComponent.hpp + sources/System/EndCondition/EndConditionSystem.hpp + sources/System/EndCondition/EndConditionSystem.cpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp new file mode 100644 index 00000000..a34defa8 --- /dev/null +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -0,0 +1,21 @@ + +#include "EndConditionSystem.hpp" +#include +#include "Runner/Runner.hpp" + +namespace BBM { + + EndConditionSystem::EndConditionSystem(WAL::Wal &wal) + : System(wal) + {} + + void EndConditionSystem::onSelfUpdate() + { + unsigned int alivePlayersCount = 0; + + for (auto & [_ , healthComponent]: this->_wal.getScene()->view()) + alivePlayersCount += (healthComponent.getHealthPoint() != 0); + if (alivePlayersCount <= 1) + Runner::gameState.nextScene = Runner::gameState.MainMenuScene; + } +} \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.hpp b/sources/System/EndCondition/EndConditionSystem.hpp new file mode 100644 index 00000000..edd3a9d7 --- /dev/null +++ b/sources/System/EndCondition/EndConditionSystem.hpp @@ -0,0 +1,26 @@ + +#pragma once + +#include "System/System.hpp" +#include "Component/Score/ScoreComponent.hpp" +#include "Component/Health/HealthComponent.hpp" +#include "Wal.hpp" + +namespace BBM +{ + class EndConditionSystem : public WAL::System + { + public: + //! @inherit + void onSelfUpdate() override; + + //! @brief ctor + EndConditionSystem(WAL::Wal &wal); + //! @brief Default copy ctor + EndConditionSystem(const EndConditionSystem &) = default; + //! @brief Default dtor + ~EndConditionSystem() override = default; + //! @brief A SoundManager screen system can't be assigned. + EndConditionSystem &operator=(const EndConditionSystem &) = delete; + }; +}