diff --git a/assets/0007PickupStationMagie.mp3 b/assets/0007PickupStationMagie.mp3 index 0ac1a7e..3fc7ada 100644 --- a/assets/0007PickupStationMagie.mp3 +++ b/assets/0007PickupStationMagie.mp3 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:afa71a30311abaf5b82aa57a1ed6af889fb5c044e16f2848e9a134c94f29811b +oid sha256:d7dd0e1a62798011a83f7f0650d7b540d6d1a3fe54dcc9bca57eedee67dffe64 size 477312 diff --git a/assets/0008AfterSationMagie.mp3 b/assets/0008AfterSationMagie.mp3 deleted file mode 100644 index 10b4b1a..0000000 --- a/assets/0008AfterSationMagie.mp3 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8b5c44ebde9933b5be6ab494ac80708a681902cd4dcf3f9de7eaf8645e64c44a -size 425472 diff --git a/assets/0008ObjektvonderNebenstationentfernt.mp3 b/assets/0008ObjektvonderNebenstationentfernt.mp3 new file mode 100644 index 0000000..429bfd9 --- /dev/null +++ b/assets/0008ObjektvonderNebenstationentfernt.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51c18a31dd9f7b338ae2c43a41eaeb53f0a649b13fe7f750ecb01adaad991971 +size 37334 diff --git a/assets/0017AfterStationMagie.mp3 b/assets/0017AfterStationMagie.mp3 new file mode 100644 index 0000000..fb09a94 --- /dev/null +++ b/assets/0017AfterStationMagie.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b618ea2a7b01e411f4f8236c7554cbaf846576a8d1dca9a5d5ad233f6382371 +size 429312 diff --git a/src/main.cpp b/src/main.cpp index ccb1681..678b1ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,7 +143,7 @@ void loop(void) } stateMachine.update(Context(stations, sizeof(stations) / sizeof(stations[0]), deltaTime, &dfPlayer)); - String newContent = stateMachine.updateDisplay(); + String newContent = stateMachine.updateDisplay(Context(stations, sizeof(stations) / sizeof(stations[0]), deltaTime, &dfPlayer)); if (previousDisplayContent != newContent) { lcd.clear(); @@ -182,5 +182,5 @@ void setup(void) } } - dfPlayer.volume(18); + dfPlayer.volume(15); } diff --git a/src/sounds.h b/src/sounds.h index 8bdda9b..638dcb3 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -10,7 +10,7 @@ #define HACKING_STATION_MAGIE 6 #define PICKUP_STATION_MAGIE 7 -#define AFTER_MAGIE 8 +#define AFTER_MAGIE 17 // weird hack because file 8 does not seem to work... #define HACKING_STATION_BICOLA 9 #define PICKUP_STATION_BICOLA 10 diff --git a/src/state.h b/src/state.h index a9774c5..dae5be1 100644 --- a/src/state.h +++ b/src/state.h @@ -21,6 +21,6 @@ public: { } - virtual String updateDisplay() { return ""; } + virtual String updateDisplay(const Context& context) { return ""; } }; diff --git a/src/statemachine.cpp b/src/statemachine.cpp index 15142e6..7c98391 100644 --- a/src/statemachine.cpp +++ b/src/statemachine.cpp @@ -3,36 +3,44 @@ #include "context.h" StateMachine::StateMachine(State* initialState) - : currentState(initialState) {} - -StateMachine::~StateMachine() { - delete currentState; -} - -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, context); -} - -void StateMachine::putDown(const Context& context, Station* newStation) { - State* newState = currentState->putDown(context, newStation); - updateState(newState, context); -} - -void StateMachine::update(const Context& context) { - State* newState = currentState->update(context); - updateState(newState, context); -} - -String StateMachine::updateDisplay() const + : currentState(initialState) { - return currentState->updateDisplay(); +} + +StateMachine::~StateMachine() +{ + delete currentState; +} + +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, context); +} + +void StateMachine::putDown(const Context& context, Station* newStation) +{ + State* newState = currentState->putDown(context, newStation); + updateState(newState, context); +} + +void StateMachine::update(const Context& context) +{ + State* newState = currentState->update(context); + updateState(newState, context); +} + +String StateMachine::updateDisplay(const Context& context) const +{ + return currentState->updateDisplay(context); } diff --git a/src/statemachine.h b/src/statemachine.h index 0f4c72c..e9209cd 100644 --- a/src/statemachine.h +++ b/src/statemachine.h @@ -17,5 +17,5 @@ public: void putDown(const Context& context, Station* newStation); void update(const Context& context); - String updateDisplay() const; + String updateDisplay(const Context& context) const; }; diff --git a/src/states.cpp b/src/states.cpp index db5f72a..6106eb0 100644 --- a/src/states.cpp +++ b/src/states.cpp @@ -1,10 +1,9 @@ #include "states.h" -#include - #include "state.h" #include "station.h" #include "sounds.h" +#include "text.h" Startup::Startup() = default; @@ -24,10 +23,9 @@ State* Startup::update(const Context context) return this; } -String Startup::updateDisplay() +String Startup::updateDisplay(const Context& context) { - return "Initializing:Put" - "on first station"; + return "Legg mi uf die ersti Station!"; } void Startup::activated(Context context) @@ -42,7 +40,7 @@ WaitingForGameStart::WaitingForGameStart() = default; State* WaitingForGameStart::pickedUp(const Context context) { - return new OnTheMove(context.stations + 1); // first element of the array + return new OnTheMove(context.stations + 1, context.stations); // first element of the array } State* WaitingForGameStart::update(const Context context) @@ -50,10 +48,9 @@ State* WaitingForGameStart::update(const Context context) return this; } -String WaitingForGameStart::updateDisplay() +String WaitingForGameStart::updateDisplay(const Context& context) { - return "Waiting for Game" - "Start..."; + return WAITING_FOR_START_TEXT; } void WaitingForGameStart::activated(const Context context) @@ -65,9 +62,10 @@ void WaitingForGameStart::activated(const Context context) //------------------------------------ -OnTheMove::OnTheMove(Station* targetStation) +OnTheMove::OnTheMove(Station* targetStation, Station* previousStation) { this->targetStation = targetStation; + this->previousStation = previousStation; } State* OnTheMove::putDown(const Context context, Station* newStation) @@ -81,7 +79,7 @@ State* OnTheMove::putDown(const Context context, Station* newStation) return new Hacking(this->targetStation); } - return new IncorrectStation(targetStation); + return new IncorrectStation(targetStation, previousStation); } State* OnTheMove::update(const Context context) @@ -89,15 +87,41 @@ State* OnTheMove::update(const Context context) return this; } -String OnTheMove::updateDisplay() +String OnTheMove::updateDisplay(const Context& context) { - return "On the Move... "; + const int index = context.getStationIndex(this->targetStation); + if (index == 0) + { + return TOBIONE_AFTER_TEXT; + } + else if (index == 1) + { + return MAIN_AFTER_PICKUP_TEXT; + } + else if (index == 2) + { + return MUHVELLA_AFTER_TEXT; + } + else if (index == 3) + { + return MAGIE_AFTER_TEXT; + } + else if (index == 4) + { + return BICOLA_AFTER_TEXT; + } + + return "UNDEFINED"; } void OnTheMove::activated(const Context context) { const int index = context.getStationIndex(this->targetStation); - if (index == 1) + if (index == 0) + { + context.dfPlayer->play(AFTER_TOBIONE); + } + else if (index == 1) { context.dfPlayer->play(AFTER_MAIN_STATION); } @@ -119,14 +143,15 @@ void OnTheMove::activated(const Context context) //------------------------------------ -IncorrectStation::IncorrectStation(Station* targetStation) +IncorrectStation::IncorrectStation(Station* targetStation, Station* previousStation) { this->targetStation = targetStation; + this->previousStation = previousStation; } State* IncorrectStation::pickedUp(const Context context) { - return new OnTheMove(this->targetStation); // todo fix nullptr + return new OnTheMove(this->targetStation, previousStation); } State* IncorrectStation::update(const Context context) @@ -134,9 +159,9 @@ State* IncorrectStation::update(const Context context) return this; } -String IncorrectStation::updateDisplay() +String IncorrectStation::updateDisplay(const Context& context) { - return "Wrong Station! "; + return WRONG_STATION_TEXT; } void IncorrectStation::activated(const Context context) @@ -174,9 +199,26 @@ State* Hacking::update(const Context context) return this; } -String Hacking::updateDisplay() +String Hacking::updateDisplay(const Context& context) { - return "Hacking B)"; + auto currentStationIndex = context.getStationIndex(this->currentStation); + if (currentStationIndex == 1) + { + return MUHVELLA_HACKING_TEXT; + } + if (currentStationIndex == 2) + { + return MAGIE_HACKING_TEXT; + } + if (currentStationIndex == 3) + { + return BICOLA_HACKING_TEXT; + } + if (currentStationIndex == 4) + { + return TOBIONE_HACKING_TEXT; + } + return "UNDEFINED"; } void Hacking::activated(const Context context) @@ -199,7 +241,7 @@ void Hacking::activated(const Context context) } if (currentStationIndex == 4) { - timer = Timer(39000, false); + timer = Timer(40000, false); context.dfPlayer->play(HACKING_STATION_TOBIONE); } timer.start(); @@ -228,9 +270,9 @@ State* Complain::update(Context context) return this; } -String Complain::updateDisplay() +String Complain::updateDisplay(const Context& context) { - return "Put me back!!"; + return COMPLAIN_TEXT; } void Complain::activated(Context context) @@ -249,7 +291,7 @@ WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStati State* WaitingForPickup::pickedUp(Context context) { - return new OnTheMove(targetStation); + return new OnTheMove(targetStation, currentStation); } State* WaitingForPickup::update(Context context) @@ -257,9 +299,25 @@ State* WaitingForPickup::update(Context context) return this; } -String WaitingForPickup::updateDisplay() +String WaitingForPickup::updateDisplay(const Context& context) { - return "Pick me up "; + auto currentStationIndex = context.getStationIndex(this->currentStation); + if (currentStationIndex == 1) + { + return MUHVELLA_PICKUP_TEXT; + } + if (currentStationIndex == 2) + { + return MAGIE_PICKUP_TEXT; + } + if (currentStationIndex == 3) + { + return BICOLA_PICKUP_TEXT; + } + if (currentStationIndex == 4) + { + return TOBIONE_PICKUP_TEXT; + } } void WaitingForPickup::activated(Context context) @@ -293,13 +351,13 @@ End::End(): timer(Timer(0, false)) State* End::pickedUp(const Context context) { - // todo to be discussed if this is the expected outcome... - return new OnTheMove(context.stations + 1); // starting game early + // todo complain + return new Complain(context.stations); } State* End::update(const Context context) { - bool done = timer.update(context.delta); + const bool done = timer.update(context.delta); if (done) { return new WaitingForGameStart(); @@ -307,13 +365,14 @@ State* End::update(const Context context) return this; } -String End::updateDisplay() +String End::updateDisplay(const Context& context) { - return "END..."; + return END_TEXT; } void End::activated(const Context context) { context.dfPlayer->play(END); - timer = Timer(27000, false); + timer = Timer(38000, false); + timer.start(); } diff --git a/src/states.h b/src/states.h index ac28ee1..33b09a4 100644 --- a/src/states.h +++ b/src/states.h @@ -12,7 +12,7 @@ public: Startup(); State* putDown(Context context, Station* newStation) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -23,7 +23,7 @@ public: WaitingForGameStart(); State* pickedUp(Context context) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -31,12 +31,13 @@ class OnTheMove final : public State { private: Station* targetStation; - + Station* previousStation; + public: - explicit OnTheMove(Station* targetStation); + explicit OnTheMove(Station* targetStation, Station* previousStation); State* putDown(Context context, Station* newStation) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -44,12 +45,13 @@ class IncorrectStation final : public State { private: Station* targetStation; + Station* previousStation; public: - explicit IncorrectStation(Station* targetStation); + explicit IncorrectStation(Station* targetStation, Station* previousStation); State* pickedUp(Context context) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -64,7 +66,7 @@ public: explicit Hacking(Station* currentStation); State* pickedUp(Context context) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -77,7 +79,7 @@ public: explicit Complain(Station* currentStation); State* putDown(Context context, Station* newStation) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -91,7 +93,7 @@ public: WaitingForPickup(Station* currentStation, Station* targetStation); State* pickedUp(Context context) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; @@ -103,6 +105,6 @@ public: End(); State* pickedUp(Context context) override; State* update(Context context) override; - String updateDisplay() override; + String updateDisplay(const Context& context) override; void activated(Context context) override; }; diff --git a/src/text.h b/src/text.h new file mode 100644 index 0000000..47a8ea4 --- /dev/null +++ b/src/text.h @@ -0,0 +1,29 @@ +#pragma once + +#define WAITING_FOR_START_TEXT "Lupf mich uf" +#define MAIN_AFTER_PICKUP_TEXT "Danke :D <3 Lueg chli ume" + +#define MUHVELLA_HACKING_TEXT "Eifach ligge lahBitte warte" +#define MUHVELLA_PICKUP_TEXT "Los! Witer =O" +#define MUHVELLA_AFTER_TEXT "Ufd Suechi! Gids Suppe? :P" + +#define MAGIE_HACKING_TEXT "Wart rasch ^^ " +#define MAGIE_PICKUP_TEXT "Und witer gahts " +#define MAGIE_AFTER_TEXT "Yoga und Chrueter? :/" + +#define BICOLA_HACKING_TEXT "Mues chli sueche" +#define BICOLA_PICKUP_TEXT "Und witer!" +#define BICOLA_AFTER_TEXT "Fast gschafft :,)" + +#define TOBIONE_HACKING_TEXT "So nah und doch so fern -.-" +#define TOBIONE_PICKUP_TEXT "Endspurt!" +#define TOBIONE_AFTER_TEXT "goi mer wieder hei" + +#define WRONG_STATION_TEXT "falschi Station" +#define COMPLAIN_TEXT "Wieder zrug stelle" + +#define END_TEXT "DU HESCH ES GSCHAFFT!!!" + + + +