diff --git a/src/main.cpp b/src/main.cpp index 04ce725..8c2245a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,6 +180,5 @@ void setup(void) } } - // dfPlayer.volume(15); - // dfPlayer.play(1); + dfPlayer.volume(7); } diff --git a/src/state.h b/src/state.h index b3d8160..5d0b1d7 100644 --- a/src/state.h +++ b/src/state.h @@ -13,5 +13,7 @@ public: virtual State* putDown(Context context, Station* newStation) { return this; } virtual State* update(Context context) { return this; } + virtual void activated(Context context) { } + virtual String updateDisplay() { return ""; } }; diff --git a/src/statemachine.cpp b/src/statemachine.cpp index b558512..15142e6 100644 --- a/src/statemachine.cpp +++ b/src/statemachine.cpp @@ -9,26 +9,27 @@ StateMachine::~StateMachine() { delete currentState; } -void StateMachine::updateState(State* newState) { +void StateMachine::updateState(State* newState, const Context& context) { if (newState != currentState) { delete currentState; currentState = newState; + currentState->activated(context); } } void StateMachine::pickedUp(const Context& context) { State* newState = currentState->pickedUp(context); - updateState(newState); + updateState(newState, context); } void StateMachine::putDown(const Context& context, Station* newStation) { State* newState = currentState->putDown(context, newStation); - updateState(newState); + updateState(newState, context); } void StateMachine::update(const Context& context) { State* newState = currentState->update(context); - updateState(newState); + updateState(newState, context); } String StateMachine::updateDisplay() const diff --git a/src/statemachine.h b/src/statemachine.h index f16b413..0f4c72c 100644 --- a/src/statemachine.h +++ b/src/statemachine.h @@ -7,7 +7,7 @@ class StateMachine { private: State* currentState; - void updateState(State* newState); + void updateState(State* newState, const Context& context); public: StateMachine(State* initialState); diff --git a/src/states.cpp b/src/states.cpp index 5ac1241..2aa65be 100644 --- a/src/states.cpp +++ b/src/states.cpp @@ -1,6 +1,7 @@ #include "states.h" #include "state.h" #include "station.h" +#include "sounds.h" Startup::Startup() = default; @@ -26,6 +27,10 @@ String Startup::updateDisplay() "on first station"; } +void Startup::activated(Context context) +{ +} + //------------------------------------ @@ -48,6 +53,11 @@ String WaitingForGameStart::updateDisplay() "Start..."; } +void WaitingForGameStart::activated(const Context context) +{ + context.dfPlayer->play(IDLE); +} + //------------------------------------ @@ -81,6 +91,18 @@ String OnTheMove::updateDisplay() 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! "; } +void IncorrectStation::activated(Context context) +{ +} + //------------------------------------ @@ -139,6 +165,11 @@ String Hacking::updateDisplay() 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!!"; } +void Complain::activated(Context context) +{ +} + //------------------------------------ @@ -192,6 +227,14 @@ String WaitingForPickup::updateDisplay() return "Pick me up "; } +void WaitingForPickup::activated(Context context) +{ +} + + +//------------------------------------ + + End::End() = default; @@ -211,3 +254,8 @@ String End::updateDisplay() { return "END..."; } + +void End::activated(Context context) +{ + context.dfPlayer->play(GAME_WON); +} diff --git a/src/states.h b/src/states.h index 40b6015..f89b856 100644 --- a/src/states.h +++ b/src/states.h @@ -13,6 +13,7 @@ public: State* putDown(Context context, Station* newStation) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; @@ -23,6 +24,7 @@ public: State* pickedUp(Context context) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; class OnTheMove final : public State @@ -35,6 +37,7 @@ public: State* putDown(Context context, Station* newStation) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; class IncorrectStation final : public State @@ -47,6 +50,7 @@ public: State* pickedUp(Context context) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; @@ -61,6 +65,7 @@ public: State* pickedUp(Context context) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; class Complain final : public State @@ -73,6 +78,7 @@ public: State* putDown(Context context, Station* newStation) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; class WaitingForPickup final : public State @@ -86,6 +92,7 @@ public: State* pickedUp(Context context) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; }; class End final : public State @@ -95,4 +102,5 @@ public: State* pickedUp(Context context) override; State* update(Context context) override; String updateDisplay() override; + void activated(Context context) override; };