Included Level completion screen, resolves #6

pull/14/head
Dennis Bücker 1 year ago
parent 0ad5ff7aac
commit 6cfb7228f5
  1. 9
      src/DisplayModeLayouts.h
  2. 109
      src/EnterColorSequence.cpp
  3. 5
      src/SimonSays.cpp
  4. 2
      src/SimonSays.h

@ -18,6 +18,15 @@ static unsigned const int DisplayLayoutX[25] =
1, 0, 0, 0, 1,
};
static unsigned const int DisplayLayoutCheckmark[25] =
{
0, 0, 0, 0, 0,
0, 0, 0, 0, 1,
0, 1, 0, 1, 0,
0, 0, 1, 0, 0,
0, 0, 0, 0, 0,
};
static unsigned const int DisplayLayoutPlayButton[25] =
{
1, 0, 1, 0, 0,

@ -1,5 +1,6 @@
#include "SimonSays.h"
#include "MCUInfo.h"
#include "DisplayModeLayouts.h"
#include <FastLED.h> // For color management
@ -38,6 +39,8 @@ EnterColorSequence::EnterColorSequence() :
void EnterColorSequence::enter(SimonSays & simonSays){
// Reset game to no input yet
inputStarted = false;
levelCompleted = false;
ticksTillNextLevel = 50;
inputSequencePosition = 0;
inputActiveColor = 0;
@ -140,7 +143,6 @@ void EnterColorSequence::enter(SimonSays & simonSays){
case 6:
simonSays.simonDisplay.setDisplayMode(6);
break;
default:
simonSays.simonDisplay.setDisplayMode(0);
break;
@ -160,60 +162,73 @@ void EnterColorSequence::leave(SimonSays &simonSays)
void EnterColorSequence::update(SimonSays &simonSays)
{
// if (!inputStarted) {
// // Only start,
// simonSays.simonDisplay.displayOneColor(CRGB::Green);
// //Serial.println("Game not started condition.");
// if (M5.Btn.wasPressed())
// {
// inputStarted = true;
// }
// else
// {
// return;
// }
// }
// check for short press
if (M5.Btn.wasReleased())
if (!levelCompleted)
{
inputActiveColor = (inputActiveColor + 1) % numberOfUniqueColors;
simonSays.simonDisplay.setActiveColor(arrayOfUniqueColors[inputActiveColor]);
// Debug for selection
Serial.print("Input position: ");
Serial.println(inputSequencePosition);
Serial.print("Current color: ");
Serial.println(arrayOfUniqueColors[inputActiveColor]);
// if (!inputStarted) {
// // Only start,
// simonSays.simonDisplay.displayOneColor(CRGB::Green);
// //Serial.println("Game not started condition.");
// if (M5.Btn.wasPressed())
// {
// inputStarted = true;
// }
// else
// {
// return;
// }
// }
// check for short press
if (M5.Btn.wasReleased())
{
inputActiveColor = (inputActiveColor + 1) % numberOfUniqueColors;
simonSays.simonDisplay.setActiveColor(arrayOfUniqueColors[inputActiveColor]);
}
// Debug for selection
Serial.print("Input position: ");
Serial.println(inputSequencePosition);
Serial.print("Current color: ");
Serial.println(arrayOfUniqueColors[inputActiveColor]);
// check for long press
if (M5.Btn.wasReleaseFor(MCUInfo::longButtonPress))
{
// 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
// check for long press
if (M5.Btn.wasReleaseFor(MCUInfo::longButtonPress))
{
// 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) {
levelCompleted = true;
simonSays.simonDisplay.setDisplayMode(0); // set display mode to custom
}
}
else {
// Enter loose state and show s.th.
// Advance sequence counter
inputSequencePosition++;
// Reset game
simonSays.resetGameAfterLoose();
// 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();
}
else
{
// This code will run, if level is completed
ticksTillNextLevel--; // decrese tick counter
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutCheckmark, true, 2, 10, 1); // 2 colors: highlight colors, 1: green, 10:black, // needs custom mode
if (ticksTillNextLevel <= 0)
{
simonSays.advanceLevel();
}
}
}

@ -168,6 +168,7 @@ void SimonSays::advanceLevel() {
// Goal is reached, go to win state
winStatus = true;
gameFinishedStatus = true;
goToNextPhase(); // this will trigger the result screen
return;
}
@ -175,5 +176,7 @@ void SimonSays::advanceLevel() {
Serial.println(currentLevel);
generateNewSequence(); // This will generate a new random sequence.
stateList[currentState]->enter(*this);
//stateList[currentState]->enter(*this); // This will trigger the recalculation of unique elements
goToNextPhase(); // this will restart to input
}

@ -44,6 +44,8 @@ class EnterColorSequence final : public GameState {
int inputStarted;
int inputSequencePosition; // will track advancement of the input
int inputActiveColor; // will track selected color
bool levelCompleted; // used to show a checkmark for some time
int ticksTillNextLevel; // time specified how long checkmark is shown
int numberOfUniqueColors; // Will be determined from the sequence
int arrayOfUniqueColors[MCUInfo::maxColorArrayLength]; // will contain an array of all unique colors
};

Loading…
Cancel
Save