Simple level dynamic and improved display.

Input of sequence possible.
pull/14/head
Dennis Bücker 1 year ago
parent 845660d26e
commit 5f244318f3
  1. 37
      src/EnterColorSequence.cpp
  2. 37
      src/ShowColorSequence.cpp
  3. 17
      src/SimonSays.cpp
  4. 6
      src/SimonSays.h

@ -174,26 +174,41 @@ void EnterColorSequence::update(SimonSays &simonSays)
{
inputActiveColor = (inputActiveColor + 1) % numberOfUniqueColors;
simonSays.simonDisplay.setActiveColor(arrayOfUniqueColors[inputActiveColor]);
// Debug for selection
Serial.print("Input position: ");
Serial.println(inputActiveColor);
Serial.print("Current color: ");
Serial.println(arrayOfUniqueColors[inputActiveColor]);
// Debug print outcome
Serial.print("Unique elements: ");
for (int i = 0; i < numberOfUniqueColors; i++)
{
Serial.print(arrayOfUniqueColors[i]);
Serial.print(" ");
}
Serial.println();
Serial.print("Number of unique elements: ");
Serial.println(numberOfUniqueColors);
}
// check for long press
if (M5.Btn.wasReleaseFor(MCUInfo::longButtonPress))
{
simonSays.simonDisplay.setActiveColor(5);
// Check if selected color was correct !-> loose condition + restart
// advance sequence counter
// check if sequence ready
// --> advance level
if (arrayOfUniqueColors[inputActiveColor] == simonSays.currentSequence[inputSequencePosition]) {
// show green flash as correct input, maybe enter this earlier after pressdown already
// Advance sequence counter
inputSequencePosition++;
// Check for game End condition
if (inputSequencePosition == simonSays.currentSequenceLength) {
simonSays.advanceLevel();
simonSays.goToNextPhase();
}
}
else {
// Enter loose state and show s.th.
// Reset game
simonSays.resetGameAfterLoose();
}
}
}

@ -3,7 +3,8 @@
ShowColorSequence::ShowColorSequence():
positionDisplay{0},
speed{10},
ticksTillNextColor{100}
ticksTillNextColor{100},
lastDisplayWasColor{false}
{}
void ShowColorSequence::enter(SimonSays & simonSays)
@ -21,20 +22,28 @@ void ShowColorSequence::update(SimonSays & simonSays)
}
else
{
simonSays.simonDisplay.displayOneColorById(simonSays.currentSequence[positionDisplay]);
if (!lastDisplayWasColor) {
simonSays.simonDisplay.displayOneColorById(simonSays.currentSequence[positionDisplay]);
Serial.print("Current color is: ");
Serial.println(simonSays.currentSequence[positionDisplay]);
Serial.print("pos display: ");
Serial.println(positionDisplay);
positionDisplay += 1;
if (positionDisplay > simonSays.currentSequenceLength)
{
simonSays.goToNextPhase();
return;
Serial.print("Current color is: ");
Serial.println(simonSays.currentSequence[positionDisplay]);
Serial.print("pos display: ");
Serial.println(positionDisplay);
positionDisplay += 1;
if (positionDisplay > simonSays.currentSequenceLength)
{
simonSays.goToNextPhase();
return;
}
ticksTillNextColor = 100; //TODO: Set this by selected level
lastDisplayWasColor = true;
}
ticksTillNextColor=10; //TODO: Set this by selected level
else {
simonSays.simonDisplay.displayOneColor(CRGB::Black);
ticksTillNextColor = 25;
lastDisplayWasColor = false;
}
}
}

@ -15,7 +15,7 @@ SimonSays::SimonSays(SimonDisplay & _simonDisplay):
&enterColorSequence
},
currentState{0},
currentLevel{0},
simonDisplay(_simonDisplay)
{
@ -33,7 +33,7 @@ void SimonSays::begin() {
currentSequenceLength = 4; // change this adjusting to level
generateNewSequence(); // This will generate a new random sequence.
stateList[currentState]->enter(*this);
Serial.println(sizeof(stateList) / sizeof(stateList[0]));
//Serial.println(sizeof(stateList) / sizeof(stateList[0]));
}
void SimonSays::goToNextPhase() {
@ -59,4 +59,17 @@ void SimonSays::generateNewSequence() {
for (int i = 0; i < length; i++) {
currentSequence[i] = newSequence[i];
}
}
void SimonSays::resetGameAfterLoose() {
currentState = 0; // Set to show color sequence
begin(); // Restart again
}
void SimonSays::advanceLevel() {
currentLevel++;
Serial.print("Current Level is ");
Serial.println(currentLevel);
begin(); // only restart at this time
}

@ -29,6 +29,7 @@ class ShowColorSequence final : public GameState {
int positionDisplay;
int speed;
int ticksTillNextColor;
bool lastDisplayWasColor;
};
class EnterColorSequence final : public GameState {
@ -38,7 +39,7 @@ class EnterColorSequence final : public GameState {
void update(SimonSays &simonSays) override;
void leave(SimonSays &simonSays) override;
private:
private :
int inputStarted;
int inputSequencePosition; // will track advancement of the input
int inputActiveColor; // will track selected color
@ -63,10 +64,13 @@ public:
void begin();
void goToNextPhase();
void update();
void resetGameAfterLoose();
void advanceLevel();
// Game logic
int currentSequence[10];
int currentSequenceLength;
int currentLevel;
// Display device logic for LEDs etc
SimonDisplay &simonDisplay;

Loading…
Cancel
Save