Sequence generation

pull/14/head
Dennis Bücker 1 year ago
parent 5f244318f3
commit ab9b6b04bb
  1. 28
      src/SimonSays.cpp

@ -15,6 +15,8 @@ SimonSays::SimonSays(SimonDisplay & _simonDisplay):
&enterColorSequence
},
currentState{0},
currentSequence{999,999,999,999,999,999,999,999,999,999}, // dummy sequence of 10 entries
currentSequenceLength{0},
currentLevel{0},
simonDisplay(_simonDisplay)
@ -30,7 +32,7 @@ void SimonSays::update() {
void SimonSays::begin() {
// Some starting logic
currentSequenceLength = 4; // change this adjusting to level
currentLevel = 0; // Reset Level to 0
generateNewSequence(); // This will generate a new random sequence.
stateList[currentState]->enter(*this);
//Serial.println(sizeof(stateList) / sizeof(stateList[0]));
@ -52,13 +54,20 @@ void SimonSays::goToNextPhase() {
}
void SimonSays::generateNewSequence() {
int maxId = 8;
// TODO: Make random sequence
int newSequence[10] = {0,1,1,0,3,4,5,6,7,8};
int length = sizeof(currentSequence)/sizeof(currentSequence[0]);
for (int i = 0; i < length; i++) {
currentSequence[i] = newSequence[i];
// Values will be generated by Level property
currentSequenceLength = 6;
int numberOfColors = 3;
Serial.print("Generated sequence ");
for (int i = 0; i < currentSequenceLength; i++)
{
currentSequence[i] = random(numberOfColors);
Serial.print(currentSequence[i]);
Serial.print(" ");
}
Serial.print(" with ");
Serial.print(currentSequenceLength);
Serial.println(" members.");
}
void SimonSays::resetGameAfterLoose() {
@ -70,6 +79,7 @@ void SimonSays::advanceLevel() {
currentLevel++;
Serial.print("Current Level is ");
Serial.println(currentLevel);
begin(); // only restart at this time
generateNewSequence(); // This will generate a new random sequence.
stateList[currentState]->enter(*this);
}
Loading…
Cancel
Save