Include multiple lives to resolve #9

pull/14/head
Dennis Bücker 1 year ago
parent de9c48a201
commit d0f76fc5d1
  1. 9
      src/DisplayModeLayouts.h
  2. 40
      src/EnterColorSequence.cpp
  3. 2
      src/MCUInfo.h
  4. 23
      src/ShowColorSequence.cpp
  5. 3
      src/SimonSays.h

@ -45,6 +45,15 @@ static unsigned const int DisplayLayoutPlayButtonSmall[25] =
0, 0, 0, 0, 0,
};
static unsigned const int DisplayLayoutPlayButtonLifeIndication[25] =
{
0, 0, 0, 0, 0,
0, 2, 0, 1, 0,
0, 3, 0, 1, 1,
0, 4, 0, 1, 0,
0, 0, 0, 0, 0,
};
static unsigned const int DisplayLayoutOneColor[25] =
{
1, 1, 1, 1, 1,

@ -32,6 +32,8 @@ EnterColorSequence::EnterColorSequence() :
inputStarted{false},
inputSequencePosition{0},
inputActiveColor{0},
levelCompleted{false},
levelSuccess{false},
numberOfUniqueColors{0}, // Will be determined from the sequence
arrayOfUniqueColors{0,0,0,0,0,0,0,0,0,0} // length of MCUInfo::maxColorArrayLength
{}
@ -40,6 +42,7 @@ void EnterColorSequence::enter(SimonSays & simonSays){
// Reset game to no input yet
inputStarted = false;
levelCompleted = false;
levelSuccess = false;
ticksTillNextLevel = 50;
inputSequencePosition = 0;
inputActiveColor = 0;
@ -209,27 +212,46 @@ void EnterColorSequence::update(SimonSays &simonSays)
// Check for game End condition
if (inputSequencePosition == simonSays.currentSequenceLength) {
levelCompleted = true;
simonSays.simonDisplay.setDisplayMode(0); // set display mode to custom
levelSuccess = true;
}
}
else {
// Report an error to restart sequence if lifes left:
simonSays.reportError();
// Reset game and Enter loose state
//simonSays.resetGameAfterLoose();
// An error was made, this will go to error mode
levelCompleted = true;
levelSuccess = false;
}
}
}
else
{
// This code will run, if level is completed
simonSays.simonDisplay.setDisplayMode(0); // set display mode to custom
ticksTillNextLevel--; // decrese tick counter
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutCheckmark, true, 2, 10, 1); // 2 colors: highlight colors, 1: green, 10:black, // needs custom mode
if (levelSuccess)
{
// show green checkmark if success
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutCheckmark, true, 2, 10, 1); // 2 colors: highlight colors, 1: green, 10:black, // needs custom mode
}
else
{
// show red X if completed by error
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutX, true, 2, 10, 0); // 2 colors: highlight colors, 0: red, 10:black, // needs custom mode
}
if (ticksTillNextLevel <= 0)
{
simonSays.advanceLevel();
if (levelSuccess)
{
// go to next level
simonSays.advanceLevel();
}
else
{
// Report an error to restart sequence if lifes left:
simonSays.reportError();
// Reset game and Enter loose state
//simonSays.resetGameAfterLoose();
}
}
}
}

@ -9,7 +9,7 @@ struct MCUInfo
static constexpr int maxColorArrayLength = 10; //maximal array length
static constexpr int initialGameLifes = 3; // lifes to start game with
static constexpr int maxLevel = 2;//10; // Maximum Level number after game is going to 'win' state.
static constexpr int maxLevel = 10; // Maximum Level number after game is going to 'win' state.
};

@ -24,7 +24,28 @@ void ShowColorSequence::update(SimonSays & simonSays)
if (!sequenceDisplayHasStartedBool)
{
// Display play button
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonSmall, true, 2, 10, 9); // highlight colors, 9: white, 10:black
//simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonSmall, true, 2, 10, 9); // highlight colors, 9: white, 10:black
switch (simonSays.gameLifes)
{
// Case switches inital display, depending on number of lifes
case 3:
// all (3) lifes remaining
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonLifeIndication, true, 5, 10, 9, 1, 1, 1); // highlight colors, 9: white, 10:black, 1: green, 0: red this button needs 5 colors
break;
case 2:
// two (2) lifes remaining
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonLifeIndication, true, 5, 10, 9, 0, 1, 1); // highlight colors, 9: white, 10:black, 1: green, 0: red this button needs 5 colors
break;
case 1:
// one (1) lifes remaining
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonLifeIndication, true, 5, 10, 9, 0, 0, 1); // highlight colors, 9: white, 10:black, 1: green, 0: red this button needs 5 colors
break;
case 0:
// no (0) lifes remaining
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonLifeIndication, true, 5, 10, 9, 0, 0, 0); // highlight colors, 9: white, 10:black, 1: green, 0: red this button needs 5 colors
break;
}
if (M5.Btn.wasPressed())
{

@ -44,7 +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
bool levelCompleted; // color entering is finished?
bool levelSuccess; // This indicates if level was finished successfull
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