void replay_controller::update_replay_ui() { //check if we have all buttons - if someone messed with theme then some buttons may be missing //if any of the buttons is missing, we just disable every one if(!replay_ui_has_all_buttons()) { gui::button *play_b = play_button(), *stop_b = stop_button(), *reset_b = reset_button(), *play_turn_b = play_turn_button(), *play_side_b = play_side_button(); if(play_b) { play_b->enable(false); } if(stop_b) { stop_b->enable(false); } if(reset_b) { reset_b->enable(false); } if(play_turn_b) { play_turn_b->enable(false); } if(play_side_b) { play_side_b->enable(false); } } }
void replay_controller::replay_ui_playback_should_start() { if(!replay_ui_has_all_buttons()) return; play_button()->enable(false); reset_button()->enable(false); play_turn_button()->enable(false); play_side_button()->enable(false); }
void replay_controller::reset_replay_ui() { if(!replay_ui_has_all_buttons()) return; play_button()->enable(true); stop_button()->enable(true); reset_button()->enable(true); play_turn_button()->enable(true); play_side_button()->enable(true); }
void replay_controller::replay_ui_playback_should_stop() { if(!replay_ui_has_all_buttons()) return; if(!recorder.at_end()) { play_button()->enable(true); reset_button()->enable(true); play_turn_button()->enable(true); play_side_button()->enable(true); play_button()->release(); play_turn_button()->release(); play_side_button()->release(); } else { reset_button()->enable(true); stop_button()->enable(false); } if(!is_playing_) { //user interrupted stop_button()->release(); } }
bool replay_ui_has_all_buttons() { return play_button() && stop_button() && reset_button() && play_turn_button() && play_side_button(); }
int main(int argc, char *argv[]) { char c; int status = 0; printf("Hello World, I'm game!\n"); status = init_display(); if (status != 0) { printf("Error: Failed to init display\n"); return status; } status = init_driver(); if (status != 0) { printf("Error: Failed to init driver\n"); destroy_display(); return status; } status = setup_handler(); if (status != 0) { printf("Error: Failed to init signal handler\n"); destroy_display(); close(file_gamepad_driver); return status; } time_handler(); /* Intializes random number generator */ srand((unsigned) time(&t)); sigset_t myset; (void) sigemptyset(&myset); while(1) { clear_LCD(); draw_game(); draw_score(p1_score, p2_score); redraw(); waitForButton(); printf("start game\n"); while((p1_score < 5) && (p2_score < 5)) { random_timer = (rand() % 3) + 2; startTimer(random_timer); waitForTimer(); random_button = (rand() % 4); draw_button(random_button, true, RED); redraw(); gettimeofday(&time_button_appears, NULL); // start timer startTimer(3); buf = 0; while((playerButtonPressed(random_button) == 0) && (timer_expired == false)) { waitForButton(); } stopTimer(); if (timer_expired == false) { time_elapsed = getGameTime(); draw_time(time_elapsed, BLUE); redraw(); } if (playerButtonPressed(random_button) == P1) { p1_score++; p1_time += time_elapsed; } else if (playerButtonPressed(random_button) == P2) { p2_score++; p2_time += time_elapsed; } draw_score(p1_score, p2_score); reset_button(random_button); redraw(); } // draw winner button_pressed = 0; if (p1_score == 5) { winner = P1; winner_time = p1_time; } else if (p2_score == 5) { winner = P2; winner_time = p2_time; } while(button_pressed == 0) { startTimer(1); winner_blink(winner, winner_time); waitForTimer(); } // print waiting waitForButton(); p1_score = 0; p1_time = 0; p2_score = 0; p2_time = 0; } }