Add new display mode

pull/14/head
Dennis Bücker 1 year ago
parent 884c44fae3
commit 5c0bb83212
  1. 3
      src/EnterColorSequence.cpp
  2. 2
      src/ShowColorSequence.cpp
  3. 24
      src/SimonDisplay.cpp
  4. 11
      src/SimonDisplay.h

@ -19,6 +19,7 @@ EnterColorSequence::EnterColorSequence() :
void EnterColorSequence::enter(SimonSays & simonSays){
// Reset game to no input yet
inputStarted = false;
simonSays.simonDisplay.setDisplayMode(1);
}
void EnterColorSequence::leave(SimonSays &simonSays)
@ -29,6 +30,6 @@ void EnterColorSequence::update(SimonSays &simonSays)
{
if (!inputStarted) {
simonSays.simonDisplay.displayOneColor(CRGB::Green);
Serial.println("Game not started condition.");
//Serial.println("Game not started condition.");
}
}

@ -29,7 +29,7 @@ void ShowColorSequence::update(SimonSays & simonSays)
Serial.println(positionDisplay);
positionDisplay += 1;
if (positionDisplay >= simonSays.currentSequenceLength)
if (positionDisplay > simonSays.currentSequenceLength)
{
simonSays.goToNextPhase();
return;

@ -2,6 +2,7 @@
namespace{
SingleColor singleColor;
CustomDisplay customDisplay;
}
SimonDisplay::SimonDisplay(M5Atom &_m5) :
@ -10,7 +11,8 @@ SimonDisplay::SimonDisplay(M5Atom &_m5) :
currentColor{0},
currentMode{0},
modeList{
&singleColor
&singleColor,
&customDisplay
}
{}
@ -42,10 +44,16 @@ void SimonDisplay::update()
modeList[currentMode]->update(*this);
}
void SimonDisplay::setDisplayMode(unsigned int _mode)
{
int numberOfModes = sizeof(modeList)/sizeof(modeList[0]);
currentMode = _mode % numberOfModes;
}
void SimonDisplay::setActiveColor(int _highlightColor)
{
currentColor=_highlightColor;
//displayOneColor(baseColors[currentColor]); // One could include the highlight bool here
//this->displayOneColor(baseColors[currentColor]); // One could include the highlight bool here
}
void SimonDisplay::drawSingleColor(int colorId, bool hightlightBool)
@ -63,16 +71,22 @@ void SimonDisplay::drawSingleColor(int colorId, bool hightlightBool)
}
}
void SimonDisplay::displayOneColor(CRGB color)
void SimonDisplay::displayOneColor(CRGB _color)
{
for (int i = 0; i <= 25; i++)
{
M5.dis.drawpix(i, color);
M5.dis.drawpix(i, _color);
}
}
void SingleColor::update(SimonDisplay & simonDisplay)
{
// Display single current color
simonDisplay.drawSingleColor(simonDisplay.currentColor, false);
//simonDisplay.drawSingleColor(simonDisplay.currentColor, false);
simonDisplay.displayOneColor(simonDisplay.baseColors[simonDisplay.currentColor]);
}
void CustomDisplay::update(SimonDisplay & simonDisplay)
{
}

@ -17,6 +17,12 @@ class SingleColor final : public DisplayMode {
void update(SimonDisplay & simonDisplay) override;
};
class CustomDisplay final : public DisplayMode
{
public:
void update(SimonDisplay &simonDisplay) override;
};
class SimonDisplay {
public:
SimonDisplay(M5Atom & _m5);
@ -26,7 +32,7 @@ class SimonDisplay {
void update();
void setActiveColor(int _highlightColor);
void setColorSequence(int _colorSequence[10]);
void setDisplayMode(int _mode);
void setDisplayMode(unsigned int _mode);
void setNumberColors(int _numberOfColors);
void displayOneColor(CRGB color);
@ -43,7 +49,8 @@ class SimonDisplay {
int currentMode;
friend class SingleColor;
DisplayMode * modeList[1];
friend class CustomDisplay;
DisplayMode * modeList[2];
int currentSequence[10];

Loading…
Cancel
Save