adds restarting state
This commit is contained in:
parent
31858bebd0
commit
6cdcca198e
6 changed files with 65 additions and 23 deletions
BIN
assets/0002AfterMainstation.mp3
(Stored with Git LFS)
BIN
assets/0002AfterMainstation.mp3
(Stored with Git LFS)
Binary file not shown.
BIN
assets/0012HackingTobione.mp3
(Stored with Git LFS)
BIN
assets/0012HackingTobione.mp3
(Stored with Git LFS)
Binary file not shown.
BIN
assets/0015End.mp3
(Stored with Git LFS)
BIN
assets/0015End.mp3
(Stored with Git LFS)
Binary file not shown.
|
@ -1,12 +1,9 @@
|
||||||
#pragma once
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <LiquidCrystal.h>
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <DFRobotDFPlayerMini.h>
|
#include <DFRobotDFPlayerMini.h>
|
||||||
#include <LiquidCrystal.h>
|
#include <LiquidCrystal.h>
|
||||||
|
|
||||||
|
|
||||||
inline void printMp3Detail(const uint8_t type, const int value)
|
inline void printMp3Detail(const uint8_t type, const int value)
|
||||||
{
|
{
|
||||||
Serial.println(); // Add a newline before printing the details
|
Serial.println(); // Add a newline before printing the details
|
||||||
|
|
|
@ -76,7 +76,7 @@ State* StartInstructions::putDown(const Context context, Station* newStation)
|
||||||
|
|
||||||
if (newStation == context.stations)
|
if (newStation == context.stations)
|
||||||
{
|
{
|
||||||
return new WaitingForGameStart(); // todo replace with Restarting
|
return new Restarting();
|
||||||
}
|
}
|
||||||
return new IncorrectStation(targetStation, context.stations);
|
return new IncorrectStation(targetStation, context.stations);
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ State* OnTheMove::putDown(const Context context, Station* newStation)
|
||||||
}
|
}
|
||||||
if (newStation == context.stations)
|
if (newStation == context.stations)
|
||||||
{
|
{
|
||||||
return new WaitingForGameStart(); // todo replace with Restarting
|
return new Restarting();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new IncorrectStation(targetStation, previousStation);
|
return new IncorrectStation(targetStation, previousStation);
|
||||||
|
@ -168,23 +168,23 @@ void OnTheMove::activated(const Context context)
|
||||||
const int index = context.getStationIndex(this->targetStation);
|
const int index = context.getStationIndex(this->targetStation);
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
context.dfPlayer->play(AFTER_TOBIONE);
|
context.dfPlayer->loop(AFTER_TOBIONE);
|
||||||
}
|
}
|
||||||
else if (index == 1)
|
else if (index == 1)
|
||||||
{
|
{
|
||||||
context.dfPlayer->play(AFTER_MAIN_STATION);
|
context.dfPlayer->loop(AFTER_MAIN_STATION);
|
||||||
}
|
}
|
||||||
else if (index == 2)
|
else if (index == 2)
|
||||||
{
|
{
|
||||||
context.dfPlayer->play(AFTER_MUHVELLA);
|
context.dfPlayer->loop(AFTER_MUHVELLA);
|
||||||
}
|
}
|
||||||
else if (index == 3)
|
else if (index == 3)
|
||||||
{
|
{
|
||||||
context.dfPlayer->play(AFTER_MAGIE);
|
context.dfPlayer->loop(AFTER_MAGIE);
|
||||||
}
|
}
|
||||||
else if (index == 4)
|
else if (index == 4)
|
||||||
{
|
{
|
||||||
context.dfPlayer->play(AFTER_BICOLA);
|
context.dfPlayer->loop(AFTER_BICOLA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,10 +316,10 @@ State* Complain::putDown(const Context context, Station* newStation)
|
||||||
}
|
}
|
||||||
return new Hacking(this->currentStation);
|
return new Hacking(this->currentStation);
|
||||||
}
|
}
|
||||||
if (newStation == context.stations) // if was incorrectly put back on main station
|
if (newStation == context.stations) // if was incorrectly put back on main station
|
||||||
{
|
{
|
||||||
return new WaitingForGameStart(); // todo return Restarting
|
return new Restarting();
|
||||||
}
|
}
|
||||||
return this; // was not put back on correct station (just keeps complaining)
|
return this; // was not put back on correct station (just keeps complaining)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,6 @@ End::End(): timer(Timer(0, false))
|
||||||
|
|
||||||
State* End::pickedUp(const Context context)
|
State* End::pickedUp(const Context context)
|
||||||
{
|
{
|
||||||
// todo complain
|
|
||||||
return new Complain(context.stations);
|
return new Complain(context.stations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +418,7 @@ State* End::update(const Context context)
|
||||||
const bool done = timer.update(context.delta);
|
const bool done = timer.update(context.delta);
|
||||||
if (done)
|
if (done)
|
||||||
{
|
{
|
||||||
return new WaitingForGameStart();
|
return new Restarting();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -435,3 +434,37 @@ void End::activated(const Context context)
|
||||||
timer = Timer(38000, false);
|
timer = Timer(38000, false);
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
Restarting::Restarting(): timer(Timer(10000, false))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
State* Restarting::pickedUp(const Context context)
|
||||||
|
{
|
||||||
|
return new StartInstructions(context.stations + 1); // starting despite not beeing in waiting for game start
|
||||||
|
}
|
||||||
|
|
||||||
|
State* Restarting::update(const Context context)
|
||||||
|
{
|
||||||
|
const bool done = timer.update(context.delta);
|
||||||
|
if (done)
|
||||||
|
{
|
||||||
|
return new WaitingForGameStart();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String Restarting::updateDisplay(const Context& context)
|
||||||
|
{
|
||||||
|
return "RESTARTING......"; // todo
|
||||||
|
}
|
||||||
|
|
||||||
|
void Restarting::activated(const Context context)
|
||||||
|
{
|
||||||
|
timer.start();
|
||||||
|
context.dfPlayer->stop();
|
||||||
|
}
|
||||||
|
|
12
src/states.h
12
src/states.h
|
@ -122,3 +122,15 @@ public:
|
||||||
String updateDisplay(const Context& context) override;
|
String updateDisplay(const Context& context) override;
|
||||||
void activated(Context context) override;
|
void activated(Context context) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Restarting final : public State
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Timer timer;
|
||||||
|
public:
|
||||||
|
Restarting();
|
||||||
|
State* pickedUp(Context context) override;
|
||||||
|
State* update(Context context) override;
|
||||||
|
String updateDisplay(const Context& context) override;
|
||||||
|
void activated(Context context) override;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue