#include "states.h" #include #include "state.h" #include "station.h" #include "sounds.h" Startup::Startup() = default; State* Startup::putDown(const Context context, Station* newStation) { const int newStationIndex = context.getStationIndex(newStation); if (newStationIndex == 0) { return new WaitingForGameStart(); } return this; } State* Startup::update(const Context context) { return this; } String Startup::updateDisplay() { return "Initializing:Put" "on first station"; } void Startup::activated(Context context) { } //------------------------------------ WaitingForGameStart::WaitingForGameStart() = default; State* WaitingForGameStart::pickedUp(const Context context) { return new OnTheMove(context.stations + 1); // first element of the array } State* WaitingForGameStart::update(const Context context) { return this; } String WaitingForGameStart::updateDisplay() { return "Waiting for Game" "Start..."; } void WaitingForGameStart::activated(const Context context) { context.dfPlayer->loop(WAITING_FOR_GAME_START); } //------------------------------------ OnTheMove::OnTheMove(Station* targetStation) { this->targetStation = targetStation; } State* OnTheMove::putDown(const Context context, Station* newStation) { if (newStation == this->targetStation) { if (targetStation == context.stations) // first station { return new End(); } return new Hacking(this->targetStation); } return new IncorrectStation(targetStation); } State* OnTheMove::update(const Context context) { return this; } 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(AFTER_MAIN_STATION); } else if (index == 2) { context.dfPlayer->play(AFTER_MUHVELLA); } else if (index == 3) { context.dfPlayer->play(AFTER_MAGIE); } else if (index == 4) { context.dfPlayer->play(AFTER_BICOLA); } } //------------------------------------ IncorrectStation::IncorrectStation(Station* targetStation) { this->targetStation = targetStation; } State* IncorrectStation::pickedUp(const Context context) { return new OnTheMove(this->targetStation); // todo fix nullptr } State* IncorrectStation::update(const Context context) { return this; } String IncorrectStation::updateDisplay() { return "Wrong Station! "; } void IncorrectStation::activated(const Context context) { context.dfPlayer->play(WRONG_STATION); } //------------------------------------ Hacking::Hacking(Station* currentStation): timer(5000, false) { this->currentStation = currentStation; this->timer.start(); } State* Hacking::pickedUp(const Context context) { return new Complain(currentStation); } State* Hacking::update(const Context context) { Serial.println(String(context.delta)); const bool done = timer.update(context.delta); if (done) { const int currentStationIndex = context.getStationIndex(currentStation); const int nextStationIndex = (currentStationIndex + 1) % context.stationCount; Station* nextStation = context.stations + nextStationIndex; return new WaitingForPickup(currentStation, nextStation); } return this; } String Hacking::updateDisplay() { return "Hacking B)"; } void Hacking::activated(const Context context) { auto currentStationIndex = context.getStationIndex(this->currentStation); if (currentStationIndex == 1) { timer = Timer(31000, false); context.dfPlayer->play(HACKING_STATION_MUHVELLA); } if (currentStationIndex == 2) { timer = Timer(33000, false); context.dfPlayer->play(HACKING_STATION_MAGIE); } if (currentStationIndex == 3) { timer = Timer(36000, false); context.dfPlayer->play(HACKING_STATION_BICOLA); } if (currentStationIndex == 4) { timer = Timer(35000, false); context.dfPlayer->play(HACKING_STATION_TOBIONE); } timer.start(); } //------------------------------------ Complain::Complain(Station* currentStation) { this->currentStation = currentStation; } State* Complain::putDown(const Context context, Station* newStation) { if (this->currentStation == newStation) // was put back on correct station { return new Hacking(this->currentStation); } return this; // was not put back on correct station (just keeps complaining) } State* Complain::update(Context context) { return this; } String Complain::updateDisplay() { return "Put me back!!"; } void Complain::activated(Context context) { } //------------------------------------ WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation) { this->currentStation = currentStation; this->targetStation = targetStation; } State* WaitingForPickup::pickedUp(Context context) { return new OnTheMove(targetStation); } State* WaitingForPickup::update(Context context) { return this; } String WaitingForPickup::updateDisplay() { return "Pick me up "; } void WaitingForPickup::activated(Context context) { auto currentStationIndex = context.getStationIndex(this->currentStation); if (currentStationIndex == 1) { context.dfPlayer->loop(PICKUP_STATION_MUHVELLA); } if (currentStationIndex == 2) { context.dfPlayer->loop(PICKUP_STATION_MAGIE); } if (currentStationIndex == 3) { context.dfPlayer->loop(PICKUP_STATION_BICOLA); } if (currentStationIndex == 4) { context.dfPlayer->loop(PICKUP_STATION_TOBIONE); } } //------------------------------------ End::End() = default; State* End::pickedUp(const Context context) { // todo what happens when we pick up here?... return this; } State* End::update(const Context context) { // todo after some time return waiting for game start... return this; } String End::updateDisplay() { return "END..."; } void End::activated(const Context context) { context.dfPlayer->play(END); }