void secret_button() { static unsigned long but1; but1 = millis(); Serial.println(F("1")); while(!digitalRead(ON_PIN)){ delay(20); if (millis() > but1 + 5000){ go_sleep(); } } but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("2")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("3")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("4")); while(!digitalRead(ON_PIN)){delay(20);} but1 = millis(); while(millis() < but1 + BUTTON1_DELAY){delay(20); if(!digitalRead(ON_PIN)){ Serial.println(F("5")); but1 = millis(); while(!digitalRead(ON_PIN)){delay(20); Serial.println(F("6")); if(millis() > but1 + 800){ Serial.println(F("Release now!")); lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("Release now!")); delay(500); lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("Press: open box")); lcd.setCursor(0,1); lcd.print(F("Hold: reset game")); delay(1000); while(digitalRead(ON_PIN)){} but1 = millis(); while(!digitalRead(ON_PIN)){delay(20);} if(millis() - but1 > 1000){ lcd.clear(); lcd.print(F("RESET GAME!")); delay(3000); target = 1; EEPROM.write(EEPROM_TARGET_INDEX, 1); break; } else { open_box(); delay(15000); close_box(); break; } } } } } } } } } } } }
int walk_map(McMap * mcMap) { int i, j, ch, r, walk; unsigned short exits; i = mcMap->prev_x; j = mcMap->prev_y; for (walk = 0; map_valid(mcMap);) { r = 4; myInfo->pos_x = i; myInfo->pos_y = j; money_show_stat("邪恶荒原"); move(r++, 0); prints ("这里是大富翁城外不远的邪恶荒原, 周围荒草凄凄, 静寂得令人毛骨悚然."); if (myInfo->health < 1) { showAt(++r, 0, "你没有足够的体力行走了...", YEA); continue; } move(t_lines - 2, 0); prints("[h 帮助]这里明显的出口是:"); exits = mcMap->map[i][j].exit; if (exits & NODE_LEFT) prints("%s、", "←"); if (exits & NODE_RIGHT) prints("%s、", "→"); if (exits & NODE_UP) prints("%s、", "↑"); if (exits & NODE_DOWN) prints("%s。", "↓"); print_item(&mcMap->map[i][j], &r); ch = igetkey(); if (ch == KEY_LEFT && (exits & NODE_LEFT)) { walk++; j--; } else if (ch == KEY_RIGHT && (exits & NODE_RIGHT)) { walk++; j++; } else if (ch == KEY_UP && (exits & NODE_UP)) { walk++; i--; } else if (ch == KEY_DOWN && (exits & NODE_DOWN)) { walk++; i++; } else if (ch == 'q' || ch == 'Q') { return 0; } else if (ch == 'h' || ch == 'H') { print_map_help(); } else if (ch == KEY_TAB) { nomoney_show_stat("邪恶荒原"); move(4, 0); print_map(mcMap, 1); pressanykey(); } else if (ch == 'k' || ch == 'K') { kill_npc(); } else if (ch == 'o') { open_box(); } else { showAt(t_lines - 1, 0, ">你要做什么?", YEA); } //更新身体状态 update_health(); if (walk % 4 == 1) { walk++; myInfo->health--; limit_cpu(); } } return 0; }
void loop() { //Serial.print(F("Free RAM1:")); Serial.println(freeRam()); // Check secret button but = !digitalRead(ON_PIN); if(but){ Serial.println(F("Button pressed")); secret_button(); } bool GPS_debug = 0; unsigned long t = millis(); while (ss.available() > 0 || t + 1100 < millis()){ gps.encode(ss.read()); GPS_debug = 1; } if (GPS_debug) { Serial.println(F("GPS received")); GPS_debug = 0; } sats_fix = gps.satellites.value(); hdop = gps.hdop.value(); position_lat = gps.location.lat(); position_lon = gps.location.lng(); //target = 3; // debug distance = gps.distanceBetween(position_lat, position_lon, target_lat[target], target_lon[target]); //distance = 4; // debug static int sim, ok; #ifdef SIMULATION if (but == 1){ sim = 1; delay (1000); } else { sim = 0; lcd.setCursor(14, 1); lcd.print(target); } if (distance > 30 && sim == 0){ #else if (distance > 30) { #endif lcd_target(lcd, target, distance, sats_fix); } else { #ifdef BUTTON_FOR_NEXT_STEP wait finish; finish.set_time(2500); finish.set_steps(2); lcd.setCursor(0, 0); if(finish.step() == 1){ lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); } if (finish.step() == 2){ lcd.setCursor(0, 0); lcd.print(F("Press the button")); lcd.setCursor(0, 1); lcd.print(F("to continue... ")); } if (but == 1){ // Go to next target target++; ok = 1; } #else lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("You are at your ")); lcd.setCursor(0, 1); lcd.print(F("current target.")); target++; delay(5000); but = 0; #endif // Open the box at the end of game if(target > NUMBER_OF_TARGETS){ lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("CONRATULATIONS! ")); delay(5000); open_box(); } else { EEPROM.write(EEPROM_TARGET_INDEX, target); } } if(millis() > update_time + 1000){ update_time = millis(); Serial.println(gps.location.lat(), 6); Serial.print(F("LAT=")); Serial.println(gps.location.lat(), 6); Serial.print(F("LONG=")); Serial.println(gps.location.lng(), 6); Serial.print(F("ALT=")); Serial.println(gps.altitude.meters()); Serial.print(F("hdop=")); Serial.println(hdop); Serial.print(F("sats=")); Serial.println(sats_fix); if(hdop < 500 && sats_fix > 4){ fix = 1; distance = gps.distanceBetween(position_lat, position_lon, TARGET_1_LAT, TARGET_1_LON); } else{ fix = 0; strength = sats_fix; //lcd_gps_signal(lcd, strength); } } if(millis() > sleep_time + SLEEP_TIME_MS){ go_sleep(); } } void go_sleep(void) { lcd.clear(); lcd.print(F("Going to sleep..")); delay(2000); pinMode(ON_PIN, OUTPUT); digitalWrite(ON_PIN, 0); }
int main(int argc, char **argv) { SDL_Event event; Uint8 mstat; int xw, yh, optc; int bombs = -1, width = -1, height = -1; struct option const longopts[] = { {"width", 1, NULL, 'w'}, {"height", 1, NULL, 'h'}, {"bombs", 1, NULL, 'b'}, {"help", 0, NULL, 'H'}, {NULL, 0, NULL, 0} }; progname = argv[0]; while ((optc = getopt_long(argc, argv, "w:h:b:H", longopts, NULL)) != -1) { switch (optc) { case 'w': width = atoi(optarg); break; case 'h': height = atoi(optarg); break; case 'b': bombs = atoi(optarg); break; case 'H': usage(0); exit(EXIT_SUCCESS); default: usage(1); exit(EXIT_FAILURE); } } usage(0); /* Use default value if invalid argument is given. */ if (width < 1 || width > 99) width = W_DEF; if (height < 1 || height > 99) height = H_DEF; if (bombs < 1 || bombs > width*height) bombs = width*height / 6; if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Error: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); init_graphic(width, height); atexit(deinit_graphic); init_game(width, height, bombs); atexit(deinit_game); start_game(); while (SDL_WaitEvent(&event) >= 0) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: if (is_gameover()) { start_game(); break; } xw = event.motion.x; yh = event.motion.y; pixel2pos(&xw, &yh); mstat = SDL_GetMouseState(NULL, NULL); if(mstat & SDL_BUTTON(1) || mstat & SDL_BUTTON(2)) open_box(get_box(xw, yh)); else if (mstat & SDL_BUTTON(3)) set_flag(get_box(xw, yh)); break; case SDL_QUIT: putchar('\n'); exit(EXIT_SUCCESS); break; default: break; /* Nothing. */ } } return 0; }