Hardware Reference
In-Depth Information
Listing 11-3. Stack It's Sketch, Part 4 of 7
void buttonInterrupt () {
while ( digitalRead(2)== LOW) {
WinState();
}
} // end buttonInterrupt
void WinState() {
button = true;
if ((cubeMove[16-level] & cubeMove[17-level])) {
Win = true;
}
else {
Win = false;
}
} // end WinState
Part 5 performs actions based on the win state when the player presses the button and increases the level.
If the win state is true , then the prior level is masked with the current to determine the amount of sprites that are in
common. If some of the sprites are not directly above the prior level, they get removed, and the new amount of sprites
is copied to the next level, making it more difficult for the player along with decreasing the time the player has to react.
If the win state is false , the game simply resets. The IncreaseLevel() function works like the one for Stop it, but the
masking of the level count is unavailable because of the array. An if statement is used in place of the mask, and when
the level reaches 17, the final pattern within cubeMove() is displayed and the game is reset. A reward function can be
called at the point the level is maxed.
Listing 11-3. Stack It's Sketch, Part 5 of 7
void checkWin() {
if (Win) {
// check prior level and set curent level to any misses and copy to next level
cubeMove[15-level] = cubeMove[16-level] = cubeMove[16-level] & cubeMove[17-level];
IncreaseLevel();
}
if (!Win) {
resetPlay ();
}
button = false;
} // end checkWin
void IncreaseLevel() {
level ++ ;
if (level >= 17) {
// display winning pattern and reset play
displaySprites();
delay (200);
resetPlay();
}
} // end IncreaseLevel
 
Search WWH ::




Custom Search