non working sequence code
This commit is contained in:
parent
662464d34d
commit
27fc0535b3
11 changed files with 286 additions and 32 deletions
|
@ -1,9 +1,14 @@
|
|||
#include "states.h"
|
||||
|
||||
#include <sequences.h>
|
||||
|
||||
#include "state.h"
|
||||
#include "station.h"
|
||||
#include "sounds.h"
|
||||
|
||||
Startup::Startup() = default;
|
||||
Startup::Startup(): State(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
State* Startup::putDown(const Context context, Station* newStation)
|
||||
{
|
||||
|
@ -16,8 +21,9 @@ State* Startup::putDown(const Context context, Station* newStation)
|
|||
return this;
|
||||
}
|
||||
|
||||
State* Startup::update(Context context)
|
||||
State* Startup::update(const Context context)
|
||||
{
|
||||
updateSeqence(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -35,15 +41,20 @@ void Startup::activated(Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
WaitingForGameStart::WaitingForGameStart() = default;
|
||||
WaitingForGameStart::WaitingForGameStart() : State(&ON_MAIN_STATION)
|
||||
{
|
||||
}
|
||||
|
||||
State* WaitingForGameStart::pickedUp(const Context context)
|
||||
{
|
||||
return new OnTheMove(context.stations + 1); // first element of the array
|
||||
return new OnTheMove(context.stations + 1, &AFTER_MAIN_STATION); // first element of the array
|
||||
}
|
||||
|
||||
State* WaitingForGameStart::update(Context context)
|
||||
State* WaitingForGameStart::update(const Context context)
|
||||
{
|
||||
// Serial.println("update wait");
|
||||
updateSeqence(context);
|
||||
// Serial.println("after");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -62,7 +73,7 @@ void WaitingForGameStart::activated(const Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
OnTheMove::OnTheMove(Station* targetStation)
|
||||
OnTheMove::OnTheMove(Station* targetStation, Sequence* sequence): State(sequence)
|
||||
{
|
||||
this->targetStation = targetStation;
|
||||
}
|
||||
|
@ -75,7 +86,7 @@ State* OnTheMove::putDown(const Context context, Station* newStation)
|
|||
{
|
||||
return new End();
|
||||
}
|
||||
return new Hacking(this->targetStation);
|
||||
return new Hacking(this->targetStation, nullptr);
|
||||
}
|
||||
|
||||
return new IncorrectStation(targetStation);
|
||||
|
@ -83,6 +94,7 @@ State* OnTheMove::putDown(const Context context, Station* newStation)
|
|||
|
||||
State* OnTheMove::update(const Context context)
|
||||
{
|
||||
updateSeqence(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -96,10 +108,11 @@ 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_MAIN_STATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.dfPlayer->play(REMOVED_FROM_SIDE_STATION);
|
||||
context.dfPlayer->play(REMOVED_FROM_SIDE_STATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,18 +120,19 @@ void OnTheMove::activated(const Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
IncorrectStation::IncorrectStation(Station* targetStation)
|
||||
IncorrectStation::IncorrectStation(Station* targetStation): State(nullptr) // todo remove nullptr
|
||||
{
|
||||
this->targetStation = targetStation;
|
||||
}
|
||||
|
||||
State* IncorrectStation::pickedUp(const Context context)
|
||||
{
|
||||
return new OnTheMove(this->targetStation);
|
||||
return new OnTheMove(this->targetStation, nullptr); // todo fix nullptr
|
||||
}
|
||||
|
||||
State* IncorrectStation::update(const Context context)
|
||||
{
|
||||
updateSeqence(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -135,7 +149,7 @@ void IncorrectStation::activated(Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
Hacking::Hacking(Station* currentStation): timer(5000, false)
|
||||
Hacking::Hacking(Station* currentStation, Sequence* sequence): State(sequence), timer(5000, false)
|
||||
{
|
||||
this->currentStation = currentStation;
|
||||
this->timer.start();
|
||||
|
@ -148,15 +162,16 @@ State* Hacking::pickedUp(const Context context)
|
|||
|
||||
State* Hacking::update(const Context context)
|
||||
{
|
||||
updateSeqence(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 new WaitingForPickup(currentStation, nextStation, nullptr);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -175,7 +190,7 @@ void Hacking::activated(const Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
Complain::Complain(Station* currentStation)
|
||||
Complain::Complain(Station* currentStation): State(nullptr)
|
||||
{
|
||||
this->currentStation = currentStation;
|
||||
}
|
||||
|
@ -184,7 +199,7 @@ State* Complain::putDown(const Context context, Station* newStation)
|
|||
{
|
||||
if (this->currentStation == newStation) // was put back on correct station
|
||||
{
|
||||
return new Hacking(this->currentStation);
|
||||
return new Hacking(this->currentStation, nullptr);
|
||||
}
|
||||
return this; // was not put back on correct station (just keeps complaining)
|
||||
}
|
||||
|
@ -207,7 +222,7 @@ void Complain::activated(Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation)
|
||||
WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation, Sequence* sequence): State(sequence)
|
||||
{
|
||||
this->currentStation = currentStation;
|
||||
this->targetStation = targetStation;
|
||||
|
@ -215,7 +230,7 @@ WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStati
|
|||
|
||||
State* WaitingForPickup::pickedUp(Context context)
|
||||
{
|
||||
return new OnTheMove(targetStation);
|
||||
return new OnTheMove(targetStation, nullptr);
|
||||
}
|
||||
|
||||
State* WaitingForPickup::update(Context context)
|
||||
|
@ -236,7 +251,10 @@ void WaitingForPickup::activated(Context context)
|
|||
//------------------------------------
|
||||
|
||||
|
||||
End::End() = default;
|
||||
End::End():State(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
State* End::pickedUp(const Context context)
|
||||
|
@ -256,7 +274,7 @@ String End::updateDisplay()
|
|||
return "END...";
|
||||
}
|
||||
|
||||
void End::activated(Context context)
|
||||
void End::activated(const Context context)
|
||||
{
|
||||
context.dfPlayer->play(GAME_WON);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue