int main(int argc, char *argv[]){ if (checkSwitch(argc, argv)) return 0; if (strcmp(argv[1], "-menu") == 0) { menu(); } else if (strcmp(argv[1], "-add") == 0) { add(argc, argv); } else if (strcmp(argv[1], "-del") == 0) { del(argc, argv); } else if (strcmp(argv[1], "-edit") == 0) { edit(argc, argv); } else if (strcmp(argv[1], "-verify") == 0) { return verify(argc, argv, 0); } else { printf("%s is an invalid switch. Please use the following syntax with a single valid switch.\n $./passweb –menu –add –del –edit –verify username password type\n", argv[1]); } return 0; }
// This can run up to 16000 times per second, but most of the time runs around 3000 times per second. void loop() { // check if system should be on checkSwitch(); // main process if(systemOn) { // inspect serial port looking for input inspectSerialPortInput(); } else { // shut down everything resetEverything(); } }
void mainWindowClickHandler(ClickRecognizerRef recognizer, void *context) { ButtonId button = click_recognizer_get_button_id(recognizer); if (s_gameState == kAwaitingDirection) { // Check the direction I just pressed if (BUTTON_ID_UP == button) checkSwitch(s_cursor.x , s_cursor.y - 1); else if (BUTTON_ID_SELECT == button) checkSwitch(s_cursor.x + 1, s_cursor.y ); else if (BUTTON_ID_DOWN == button) checkSwitch(s_cursor.x , s_cursor.y + 1); else if (BUTTON_ID_BACK == button) checkSwitch(s_cursor.x - 1, s_cursor.y ); } else { if (s_tiltMode == 0) { if (BUTTON_ID_DOWN == button) { if (++s_cursor.y >= BOARD_PIECES_Y) s_cursor.y = 0; } else if (BUTTON_ID_SELECT == button) { if (++s_cursor.x >= BOARD_PIECES_X) s_cursor.x = 0; } } else { if (BUTTON_ID_DOWN == button) s_motionCursor.y += PIECE_SUB_PIXELS; // Manipulation of white dot cursor else if (BUTTON_ID_SELECT == button) s_motionCursor.x += PIECE_SUB_PIXELS; } if (BUTTON_ID_UP == button && s_gameState == kIdle) { s_gameState = kAwaitingDirection; s_frame = ANIM_FPS-1; s_switch.first = s_cursor; } else if (BUTTON_ID_BACK == button) { pushSplashWindow(); return; } redraw(); } }
int main() { DDRA |= 0b1110; PORTA |= _BV(PA4) | _BV(PA5); uint8_t state = 0; while(1) { if(checkIter()) { PORTA ^= 1 << (++state); state %= 3; } if(checkSwitch()) PORTA ^= 0b1110; _delay_ms(100); } }
bool ProcessTimer::exec() { while(checkSwitch()) { if(m_suspend) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } try { m_timer.tick(); } catch(const componet::ExceptionBase& ex) { LOG_ERROR("timer, unexcept exception: [{}]", ex.what()); } } return true; }
static void dataHandler(AccelData* data, uint32_t num_samples) { // Update MotionCursor (the small white dot) s_motionCursor.x += data[0].x / s_tiltMode; // 0=off, 1=high, 2=low s_motionCursor.y -= data[0].y / s_tiltMode; if (s_motionCursor.x < 0) s_motionCursor.x += BOARD_SIZE_X * SUB_PIXEL; else if (s_motionCursor.x > BOARD_SIZE_X * SUB_PIXEL) s_motionCursor.x -= BOARD_SIZE_X * SUB_PIXEL; if (s_motionCursor.y < 0) s_motionCursor.y += BOARD_SIZE_Y * SUB_PIXEL; else if (s_motionCursor.y > BOARD_SIZE_Y * SUB_PIXEL) s_motionCursor.y -= BOARD_SIZE_Y * SUB_PIXEL; GPoint before = s_cursor; // Translate MotionCursor location to a cell s_cursor.x = s_motionCursor.x / (PIECE_SUB_PIXELS); //Note: bracket due to macro s_cursor.y = s_motionCursor.y / (PIECE_SUB_PIXELS); if (before.x != s_cursor.x || before.y != s_cursor.y) { checkSwitch(s_cursor.x, s_cursor.y); // Check the square i just moved into } }
bool Tela::playGame() { Ponto p1 = {-1, -1}, p2 = {-1, -1}, pDica = {-1, -1}; bool quit = false, execute = true; showGame(); if(testMove() == false) quit = true; float frame = 0; Uint32 start = SDL_GetTicks(); SDL_Rect rect0[20], rect1[20], rect2[20], rect3[20], rect4[20], rect5[20], rect6[20]; setrects(rect0, 60, 0); setrects(rect1, 62, 70); setrects(rect2, 58, 140); setrects(rect3, 58, 210); setrects(rect4, 60, 280); setrects(rect5, 64, 350); setrects(rect6, 64, 420); while( execute ) { changeLevel(); if( level == 5 ) { execute = false; return execute; } if( SDL_PollEvent( &event ) ) { Ponto tmp; //Botão esquerdo do mouse pressionado if( event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) { tmp.x = event.button.x; tmp.y = event.button.y; if((tmp.x >= 135 && tmp.x <= 250) && (tmp.y >= 480 && tmp.y <= 595)) { undoPlay(); SDL_Flip( screen ); } else if((tmp.x >= 45 && tmp.x <= 160) && (tmp.y >= 395 && tmp.y <= 505)){ pDica = getDica(); apply_surface(pDica.x, pDica.y, gems_dica, screen); SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h); } else if((tmp.x >= 30 && tmp.x <= 115) && (tmp.y >= 525 && tmp.y <= 605)){ if(showConfScreen()) { quit = true; return quit; } else { showGame(); } } else if((tmp.x >= 175 && tmp.x <= 265) && (tmp.y >= 380 && tmp.y <= 465)){ if(showInstrucoes()) { quit = true; return quit; } else { showGame(); } } else if((tmp.x >= MAT_INITIAL_POINT_X && tmp.x <= MAT_INITIAL_POINT_X + 480) && (tmp.y >= MAT_INITIAL_POINT_Y && tmp.y <= MAT_INITIAL_POINT_Y + 480)) { if(pDica.x >= 0) { apply_surface(pDica.x, pDica.y, gems, screen); SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h); } tmp.x = (tmp.x - MAT_INITIAL_POINT_X) / 60; tmp.y = (tmp.y - MAT_INITIAL_POINT_Y) / 60; if(p1.x < 0) { p1.x = tmp.y; p1.y = tmp.x; //Destaca a nova joia selecionada } else if(p2.x < 0) { if(saoAdjacentes(p1.x, p1.y, tmp.y, tmp.x)) { p2.x = tmp.y; p2.y = tmp.x; } else { //Ignora selecao //Tira o destaque da joia que tinha sido selecionada apply_surface(p1.x, p1.y, gems, screen); SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h); p1.x = tmp.y; p1.y = tmp.x; } } } //Se o usuario fechar a janela } else if( (event.type == SDL_QUIT) ) { //Encerra o programa quit = true; return quit; //Se o usuario teclar ESC } else if ( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) ) { level = 5; /* Show Game Over */ } else if( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) ) { if(audio == true) { //Pausa a musica Mix_PauseMusic(); audio = false; } else { //Toca a musica novamente Mix_ResumeMusic(); audio = true; } } } SDL_Rect offset; offset.x = matriz[p1.x][p1.y].celula.x; offset.y = matriz[p1.x][p1.y].celula.y; switch(getElement(p1.x, p1.y)) { case 1: SDL_BlitSurface( gems, &rect0[static_cast<int>(frame)], screen, &offset ); break; case 2: SDL_BlitSurface( gems, &rect1[static_cast<int>(frame)], screen, &offset ); break; case 3: SDL_BlitSurface( gems, &rect2[static_cast<int>(frame)], screen, &offset ); break; case 4: SDL_BlitSurface( gems, &rect3[static_cast<int>(frame)], screen, &offset ); break; case 5: SDL_BlitSurface( gems, &rect4[static_cast<int>(frame)], screen, &offset ); break; case 6: SDL_BlitSurface( gems, &rect5[static_cast<int>(frame)], screen, &offset ); break; case 7: SDL_BlitSurface( gems, &rect6[static_cast<int>(frame)], screen, &offset ); break; } SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h); //Velocidade de transição entre frames frame += 0.5; if(frame > 7) { frame = 0; } if(1000/FPS > SDL_GetTicks()-start) { SDL_Delay(1000/FPS-(SDL_GetTicks()-start)); } if((p1.x >= 0) && (p2.x >= 0)) { checkSwitch(p1.x, p1.y, p2.x, p2.y); contrastItem(p1.x, p1.y, matriz[p1.x][p1.y].elemento); apply_surface(p1.x, p1.y, gems, screen); SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h); p1.x = -1; p1.y = -1; p2.x = -1; p2.y = -1; if(testMove() == false) level = 5; } } return execute; }