Include Lifes to contribut to #9

pull/14/head
Dennis Bücker 1 year ago
parent 6cfb7228f5
commit de9c48a201
  1. 7
      src/EnterColorSequence.cpp
  2. 6
      src/MCUInfo.h
  3. 29
      src/SimonSays.cpp
  4. 2
      src/SimonSays.h

@ -213,10 +213,11 @@ void EnterColorSequence::update(SimonSays &simonSays)
}
}
else {
// Enter loose state and show s.th.
// Report an error to restart sequence if lifes left:
simonSays.reportError();
// Reset game
simonSays.resetGameAfterLoose();
// Reset game and Enter loose state
//simonSays.resetGameAfterLoose();
}
}

@ -5,9 +5,11 @@ struct MCUInfo
static constexpr float periodIntervalInMs = 2000.f;
static constexpr float tickIntervalInMs = periodIntervalInMs/maxTicks;
static constexpr float longButtonPress = 700; // millisecond
static constexpr float longButtonPress = 500; // millisecond
static constexpr int maxColorArrayLength = 10; //maximal array length
static constexpr int maxLevel = 10; // Maximum Level number after game is going to 'win' state.
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.
};

@ -21,6 +21,7 @@ SimonSays::SimonSays(SimonDisplay & _simonDisplay):
currentLevel{0},
currentSpeed{100},
maxLevel{MCUInfo::maxLevel},
gameLifes{MCUInfo::initialGameLifes},
gameFinishedStatus{false},
winStatus{false},
simonDisplay(_simonDisplay)
@ -153,6 +154,25 @@ void SimonSays::generateNewSequence() {
Serial.println(".");
}
void SimonSays::reportError()
{
gameLifes--;
if (gameLifes < 0)
{
// run if there was no life left
resetGameAfterLoose();
}
else
{
// restart the sequence
Serial.print("Only ");
Serial.print(gameLifes);
Serial.println(" Lifes left. Keep focused!");
goToNextPhase();
}
}
void SimonSays::resetGameAfterLoose() {
// Set game finished
@ -172,6 +192,15 @@ void SimonSays::advanceLevel() {
return;
}
if (gameLifes<MCUInfo::initialGameLifes)
{
gameLifes++;
Serial.print("You regained a life. ");
}
Serial.print("Success, now there are ");
Serial.print(gameLifes);
Serial.println(" lifes to go. Keep it on!");
Serial.print("Current Level is ");
Serial.println(currentLevel);

@ -79,6 +79,7 @@ public:
void begin();
void goToNextPhase();
void update();
void reportError();
void resetGameAfterLoose();
void advanceLevel();
@ -88,6 +89,7 @@ public:
int currentLevel;
int currentSpeed;
int maxLevel;
int gameLifes;
bool gameFinishedStatus;
bool winStatus; // Is set true, if overall Game is won.

Loading…
Cancel
Save