Add Game Loose screen to resolve #4

pull/14/head
Dennis Bücker 1 year ago
parent 552ec98b34
commit 0ad5ff7aac
  1. 2
      src/DisplayModeLayouts.h
  2. 2
      src/EnterColorSequence.cpp
  3. 40
      src/GameResultState.cpp
  4. 29
      src/GameWonState.cpp
  5. 10
      src/ShowColorSequence.cpp
  6. 7
      src/SimonDisplay.cpp
  7. 15
      src/SimonSays.cpp
  8. 5
      src/SimonSays.h

@ -1,3 +1,5 @@
#pragma once
static unsigned const int DisplayLayoutNoColor[25] =
{
0, 0, 0, 0, 0,

@ -150,6 +150,8 @@ void EnterColorSequence::enter(SimonSays & simonSays){
simonSays.simonDisplay.setNumberColors(numberOfUniqueColors);
simonSays.simonDisplay.setActiveColor(inputActiveColor);
simonSays.simonDisplay.setColorsToDisplay(arrayOfUniqueColors);
Serial.println("Please enter color sequence.");
}
void EnterColorSequence::leave(SimonSays &simonSays)

@ -0,0 +1,40 @@
#include "SimonSays.h"
#include <FastLED.h>
#include "DisplayModeLayouts.h"
GameResultState::GameResultState():
hue{0}
{}
void GameResultState::enter(SimonSays &simonSays)
{
Serial.print("Entered Game result state: ");
if (simonSays.winStatus)
{
Serial.print("Victory");
}
else
{
Serial.print("Defeat");
}
Serial.println("!");
simonSays.simonDisplay.setDisplayMode(0); // set custom mode
}
void GameResultState::update(SimonSays &simonSays)
{
if (simonSays.winStatus)
{
fill_rainbow(rainbowColors, 25, hue++);
for (int pixelIdx = 0; pixelIdx < 25; pixelIdx++)
{
simonSays.simonDisplay.drawPixel(pixelIdx, rainbowColors[pixelIdx]);
}
}
else
{
//Serial.println("Game Update defeat");
simonSays.simonDisplay.clearDisplay();
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutX, true, 2, 10, 0); // 2colors: 10: black, 0: red, will display a red X
}
}

@ -1,29 +0,0 @@
#include "SimonSays.h"
#include <FastLED.h>
GameWonState::GameWonState():
hue{0}
{}
void GameWonState::enter(SimonSays &simonSays)
{
Serial.println("Entered Game won state!");
simonSays.simonDisplay.setDisplayMode(0); // set custom mode
fill_rainbow(rainbowColors,25,hue++);
for (int pixelIdx = 0; pixelIdx <25;pixelIdx++)
{
simonSays.simonDisplay.drawPixel(pixelIdx,rainbowColors[pixelIdx]);
}
}
void GameWonState::update(SimonSays &simonSays)
{
fill_rainbow(rainbowColors, 25, hue++);
for (int pixelIdx = 0; pixelIdx < 25; pixelIdx++)
{
simonSays.simonDisplay.drawPixel(pixelIdx, rainbowColors[pixelIdx]);
}
}

@ -23,7 +23,7 @@ void ShowColorSequence::update(SimonSays & simonSays)
// Check if button was pressed once to start sequence display. if not: show red x
if (!sequenceDisplayHasStartedBool)
{
// Display x
// Display play button
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonSmall, true, 2, 10, 9); // highlight colors, 9: white, 10:black
if (M5.Btn.wasPressed())
@ -44,10 +44,10 @@ void ShowColorSequence::update(SimonSays & simonSays)
if (!lastDisplayWasColor) {
simonSays.simonDisplay.displayOneColorById(simonSays.currentSequence[positionDisplay],true);
Serial.print("Current color is: ");
Serial.println(simonSays.currentSequence[positionDisplay]);
Serial.print("pos display: ");
Serial.println(positionDisplay);
// Serial.print("Current color is: ");
// Serial.println(simonSays.currentSequence[positionDisplay]);
// Serial.print("pos display: ");
// Serial.println(positionDisplay);
positionDisplay += 1;
if (positionDisplay > simonSays.currentSequenceLength)

@ -142,6 +142,11 @@ void SimonDisplay::displayDisplayLayout(unsigned const int DisplayLayout[25], bo
clearDisplay(); // clear display first
// Serial.print("Colors are: ");
// Serial.print(colors[0]);
// Serial.print(" ");
// Serial.println(colors[1]);
for (int pixelIdx = 0; pixelIdx < 25; pixelIdx++)
{
if (DisplayLayout[pixelIdx] > numColors)
@ -162,7 +167,7 @@ void SimonDisplay::displayDisplayLayout(unsigned const int DisplayLayout[25], bo
}
}
// Possible improvement: include a switch for a highlighed color
// Possible improvement: include a switch for a highlighed color per color
}

@ -5,7 +5,7 @@
namespace {
ShowColorSequence showColorSequence;
EnterColorSequence enterColorSequence;
GameWonState gameWonState;
GameResultState gameResultState;
}
SimonSays::SimonSays(SimonDisplay & _simonDisplay):
@ -13,7 +13,7 @@ SimonSays::SimonSays(SimonDisplay & _simonDisplay):
stateList {
&showColorSequence,
&enterColorSequence,
&gameWonState
&gameResultState
},
currentState{0},
currentSequence{999,999,999,999,999,999,999,999,999,999}, // dummy sequence of 10 entries
@ -21,6 +21,7 @@ SimonSays::SimonSays(SimonDisplay & _simonDisplay):
currentLevel{0},
currentSpeed{100},
maxLevel{MCUInfo::maxLevel},
gameFinishedStatus{false},
winStatus{false},
simonDisplay(_simonDisplay)
@ -51,7 +52,7 @@ void SimonSays::goToNextPhase() {
int numberOfStates = sizeof(stateList) / sizeof(stateList[0]);
// Check if Game is won
if (winStatus)
if (gameFinishedStatus)
{
currentState = numberOfStates-1; // Set win state idx to last saved state
}
@ -153,8 +154,11 @@ void SimonSays::generateNewSequence() {
}
void SimonSays::resetGameAfterLoose() {
currentState = 0; // Set to show color sequence
begin(); // Restart again
// Set game finished
gameFinishedStatus = true;
goToNextPhase(); // this will activate the GameResult Screen
}
void SimonSays::advanceLevel() {
@ -163,6 +167,7 @@ void SimonSays::advanceLevel() {
{
// Goal is reached, go to win state
winStatus = true;
gameFinishedStatus = true;
return;
}

@ -48,10 +48,10 @@ class EnterColorSequence final : public GameState {
int arrayOfUniqueColors[MCUInfo::maxColorArrayLength]; // will contain an array of all unique colors
};
class GameWonState final : public GameState
class GameResultState final : public GameState
{
public:
GameWonState();
GameResultState();
void enter(SimonSays &simonSays) override;
void update(SimonSays &simonSays) override;
void leave(SimonSays &simonSays) override{};
@ -86,6 +86,7 @@ public:
int currentLevel;
int currentSpeed;
int maxLevel;
bool gameFinishedStatus;
bool winStatus; // Is set true, if overall Game is won.
// Display device logic for LEDs etc

Loading…
Cancel
Save