100 lines
1.7 KiB
C++
100 lines
1.7 KiB
C++
#include "chainGame.h"
|
|
#include "Arduino.h"
|
|
#include "buttons.h"
|
|
|
|
|
|
uint8_t patternIndex = 0;
|
|
bool patternFlag = false;
|
|
bool firstpattern = false;
|
|
//e_ledcolor cheatbutton = NONE;
|
|
uint16_t cheatbutton = 0;
|
|
bool cheatButtonFlag = false;
|
|
|
|
|
|
// e_ledcolor ledpattern[4] =
|
|
// {
|
|
// YELLOW,
|
|
// GREEN,
|
|
// YELLOW,
|
|
// RED};
|
|
|
|
uint16_t ledpattern[4] =
|
|
{
|
|
1,
|
|
3,
|
|
1,
|
|
2
|
|
};
|
|
|
|
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
|
|
|
|
void nextPattern(void)
|
|
{
|
|
if (patternIndex < patternlength - 1)
|
|
{
|
|
patternIndex++;
|
|
}
|
|
else
|
|
{
|
|
patternIndex = 0;
|
|
}
|
|
}
|
|
|
|
void ResetChainGame(void)
|
|
{
|
|
patternIndex = 0;
|
|
patternFlag = false;
|
|
firstpattern = false;
|
|
cheatbutton = NONE;
|
|
cheatButtonFlag = false;
|
|
}
|
|
|
|
void HandleChainGame(void)
|
|
{
|
|
if (buttonIsPressed(ledpattern[patternIndex]) && !cheatButtonFlag)
|
|
{
|
|
turnOnLed(ledpattern[patternIndex]);
|
|
patternFlag = true;
|
|
}
|
|
else if (buttonIsPressed(cheatbutton) && !patternFlag && !cheatButtonFlag)
|
|
{
|
|
turnOnLed(cheatbutton);
|
|
cheatButtonFlag = true;
|
|
}
|
|
|
|
if (!buttonIsPressed(ledpattern[patternIndex]))
|
|
{
|
|
turnOffLed(ledpattern[patternIndex]);
|
|
}
|
|
|
|
if (!buttonIsPressed(cheatbutton) && cheatButtonFlag)
|
|
{
|
|
turnOffLed(cheatbutton);
|
|
cheatButtonFlag = false;
|
|
cheatbutton = NONE;
|
|
}
|
|
|
|
if (!anybutton())
|
|
{
|
|
turnOffAllLed();
|
|
if (patternFlag)
|
|
{
|
|
patternFlag = false;
|
|
nextPattern();
|
|
}
|
|
}
|
|
|
|
//check cheatbuttons
|
|
if (buttonIsPressed(1) && (cheatbutton == NONE))
|
|
{
|
|
cheatbutton = 1;
|
|
}
|
|
else if (buttonIsPressed(2) && (cheatbutton == NONE))
|
|
{
|
|
cheatbutton = 2;
|
|
}
|
|
else if (buttonIsPressed(3) && (cheatbutton == NONE))
|
|
{
|
|
cheatbutton = 3;
|
|
}
|
|
} |