migration to platformio

This commit is contained in:
Marcel 2024-05-23 16:16:00 +02:00
commit cad91967b1
22 changed files with 2985 additions and 0 deletions

213
src/states.cpp Normal file
View file

@ -0,0 +1,213 @@
#include "states.h"
#include "state.h"
#include "station.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(Context context)
{
return this;
}
String Startup::updateDisplay()
{
return "Initializing:Put"
"on first station";
}
//------------------------------------
WaitingForGameStart::WaitingForGameStart() = default;
State* WaitingForGameStart::pickedUp(const Context context)
{
return new OnTheMove(context.stations + 1); // first element of the array
}
State* WaitingForGameStart::update(Context context)
{
return this;
}
String WaitingForGameStart::updateDisplay()
{
return "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... ";
}
//------------------------------------
IncorrectStation::IncorrectStation(Station* targetStation)
{
this->targetStation = targetStation;
}
State* IncorrectStation::pickedUp(const Context context)
{
return new OnTheMove(this->targetStation);
}
State* IncorrectStation::update(const Context context)
{
return this;
}
String IncorrectStation::updateDisplay()
{
return "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)";
}
//------------------------------------
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!!";
}
//------------------------------------
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 ";
}
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...";
}