finishes state flow and adds temp audio

This commit is contained in:
Marcel 2024-05-27 10:19:28 +02:00
parent bc5d7e1941
commit 43d31651cd
6 changed files with 65 additions and 7 deletions

View file

@ -180,6 +180,5 @@ void setup(void)
} }
} }
// dfPlayer.volume(15); dfPlayer.volume(7);
// dfPlayer.play(1);
} }

View file

@ -13,5 +13,7 @@ public:
virtual State* putDown(Context context, Station* newStation) { return this; } virtual State* putDown(Context context, Station* newStation) { return this; }
virtual State* update(Context context) { return this; } virtual State* update(Context context) { return this; }
virtual void activated(Context context) { }
virtual String updateDisplay() { return ""; } virtual String updateDisplay() { return ""; }
}; };

View file

@ -9,26 +9,27 @@ StateMachine::~StateMachine() {
delete currentState; delete currentState;
} }
void StateMachine::updateState(State* newState) { void StateMachine::updateState(State* newState, const Context& context) {
if (newState != currentState) { if (newState != currentState) {
delete currentState; delete currentState;
currentState = newState; currentState = newState;
currentState->activated(context);
} }
} }
void StateMachine::pickedUp(const Context& context) { void StateMachine::pickedUp(const Context& context) {
State* newState = currentState->pickedUp(context); State* newState = currentState->pickedUp(context);
updateState(newState); updateState(newState, context);
} }
void StateMachine::putDown(const Context& context, Station* newStation) { void StateMachine::putDown(const Context& context, Station* newStation) {
State* newState = currentState->putDown(context, newStation); State* newState = currentState->putDown(context, newStation);
updateState(newState); updateState(newState, context);
} }
void StateMachine::update(const Context& context) { void StateMachine::update(const Context& context) {
State* newState = currentState->update(context); State* newState = currentState->update(context);
updateState(newState); updateState(newState, context);
} }
String StateMachine::updateDisplay() const String StateMachine::updateDisplay() const

View file

@ -7,7 +7,7 @@
class StateMachine { class StateMachine {
private: private:
State* currentState; State* currentState;
void updateState(State* newState); void updateState(State* newState, const Context& context);
public: public:
StateMachine(State* initialState); StateMachine(State* initialState);

View file

@ -1,6 +1,7 @@
#include "states.h" #include "states.h"
#include "state.h" #include "state.h"
#include "station.h" #include "station.h"
#include "sounds.h"
Startup::Startup() = default; Startup::Startup() = default;
@ -26,6 +27,10 @@ String Startup::updateDisplay()
"on first station"; "on first station";
} }
void Startup::activated(Context context)
{
}
//------------------------------------ //------------------------------------
@ -48,6 +53,11 @@ String WaitingForGameStart::updateDisplay()
"Start..."; "Start...";
} }
void WaitingForGameStart::activated(const Context context)
{
context.dfPlayer->play(IDLE);
}
//------------------------------------ //------------------------------------
@ -81,6 +91,18 @@ String OnTheMove::updateDisplay()
return "On the Move... "; return "On the Move... ";
} }
void OnTheMove::activated(const Context context)
{
const int index = context.getStationIndex(this->targetStation);
if (index == 1)
{
context.dfPlayer->play(REMOVED_FROM_MAIN_STATION);
} else
{
context.dfPlayer->play(REMOVED_FROM_SIDE_STATION);
}
}
//------------------------------------ //------------------------------------
@ -105,6 +127,10 @@ String IncorrectStation::updateDisplay()
return "Wrong Station! "; return "Wrong Station! ";
} }
void IncorrectStation::activated(Context context)
{
}
//------------------------------------ //------------------------------------
@ -139,6 +165,11 @@ String Hacking::updateDisplay()
return "Hacking B)"; return "Hacking B)";
} }
void Hacking::activated(const Context context)
{
context.dfPlayer->play(OBJECT_PLACED_ON_MAIN_STATION);
}
//------------------------------------ //------------------------------------
@ -167,6 +198,10 @@ String Complain::updateDisplay()
return "Put me back!!"; return "Put me back!!";
} }
void Complain::activated(Context context)
{
}
//------------------------------------ //------------------------------------
@ -192,6 +227,14 @@ String WaitingForPickup::updateDisplay()
return "Pick me up "; return "Pick me up ";
} }
void WaitingForPickup::activated(Context context)
{
}
//------------------------------------
End::End() = default; End::End() = default;
@ -211,3 +254,8 @@ String End::updateDisplay()
{ {
return "END..."; return "END...";
} }
void End::activated(Context context)
{
context.dfPlayer->play(GAME_WON);
}

View file

@ -13,6 +13,7 @@ public:
State* putDown(Context context, Station* newStation) override; State* putDown(Context context, Station* newStation) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
@ -23,6 +24,7 @@ public:
State* pickedUp(Context context) override; State* pickedUp(Context context) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
class OnTheMove final : public State class OnTheMove final : public State
@ -35,6 +37,7 @@ public:
State* putDown(Context context, Station* newStation) override; State* putDown(Context context, Station* newStation) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
class IncorrectStation final : public State class IncorrectStation final : public State
@ -47,6 +50,7 @@ public:
State* pickedUp(Context context) override; State* pickedUp(Context context) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
@ -61,6 +65,7 @@ public:
State* pickedUp(Context context) override; State* pickedUp(Context context) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
class Complain final : public State class Complain final : public State
@ -73,6 +78,7 @@ public:
State* putDown(Context context, Station* newStation) override; State* putDown(Context context, Station* newStation) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
class WaitingForPickup final : public State class WaitingForPickup final : public State
@ -86,6 +92,7 @@ public:
State* pickedUp(Context context) override; State* pickedUp(Context context) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };
class End final : public State class End final : public State
@ -95,4 +102,5 @@ public:
State* pickedUp(Context context) override; State* pickedUp(Context context) override;
State* update(Context context) override; State* update(Context context) override;
String updateDisplay() override; String updateDisplay() override;
void activated(Context context) override;
}; };