Esempio n. 1
0
void Simon::loop() {
    switch (state) { 
        case Welcome: 
            welcome();
            break;
        case Ready: 
            ready();
            break;
        case Showing:
            show();
            break;
        case ListeningDown:
            listenDown();
            break;
        case ListeningUp:
            listenUp();
            break;
        case CompleteSuccess:
            celebrate();
            break;
        case Failed:
            fail();
            break;
    }
}
Esempio n. 2
0
void Simon::ready() {
    Position read = anyButtonOn();
    
    switch (read) {
        case None:
            return;
        case Top:
            difficulty = 4;
            break;
        case Right:
            difficulty = 9;
            break;
        case Bottom:
            difficulty = 14;
            break;
        case Left:
            difficulty = 29;
            break;
    }
    celebrate();
}
Esempio n. 3
0
/*
 * Main program entry point
 * Start with 8 moles and flick LEDs via rotating mask.
 * Choose a random mole to light for fraction of a second.
 * If the mole button is pushed while the LED is lit, kill the mole.
 * When all moles are dead celebrate - check button press for restart.
 */
int main(void)
{
    int molemask    = 0xff;     // live moles

    int ontime      = 1;        // flicker on time in ms
    int offtime     = 80;       // flicker off time

    int whacked     = 0;        // it's whacked?
    int direction   = 1;        // keep direction of LED mole run

    int popcount    = 6;        // initial popcount
    int countmask   = 0x0700;   // allow up to 7 mole run steps
    int popmask     = 0x7;      // only 8 LEDs, choose from rand

    int popupspot   = 0;        // show popup position
    int popuptime   = 500;      // popup on time

    /* mole run forever loop */
    for(;;)
    {
        /* nothing whacked */
        whacked = 0;
        /* seed random function with Propeller CNT */
        srand(CNT);

        /* blank moles */
        LEDOUT(0);
        /* sleep a little */
        msleep(offtime);

        /* if all moles gone, celebrate */
        while(!molemask) {
            /* make LEDs dance */
            celebrate();
            /* if button press, restart game */
            if(getButtons()) {
                molemask = 0xff;
            }
        }

        /* get popup spot */
        if(popcount-- == 0) {
            /* get random number */
            popupspot  = rand();
            /* use upper bits for popup count */
            popcount = (popupspot & countmask) >> 8;
            /* use lower popmask bits for popup mole LED */
            popupspot &= popmask;

            /* show popup and check button */
            if(molemask & (1<<popupspot)) {
                /* set LED to show a mole to whack */
                LEDOUT((1<<popupspot) & molemask);
                /* single thread limit. sample twice */
                msleep(popuptime>>1);
                whacked = getButton(popupspot);
                msleep(popuptime>>1);
                whacked |= getButton(popupspot);
                /* set back to mole mask */
                LEDOUT(molemask);
            }
        }