int main() { int choice, last_game; srand(time(0)); // Seed the randomizer with the current time. if(get_player_data() == -1) // Try to read player data from file. register_new_player(); // If there is no data, register a new player. while(choice != 7) { printf("-=[ Game of Chance Menu ]=-\n"); printf("1 - Play the Pick a Number game\n"); printf("2 - Play the No Match Dealer game\n"); printf("3 - Play the Find the Ace game\n"); printf("4 - View current high score\n"); printf("5 - Change your user name\n"); printf("6 - Reset your account at 100 credits\n"); printf("7 - Quit\n"); printf("[Name: %s]\n", player.name); printf("[You have %u credits] -> ", player.credits); scanf("%d", &choice); if((choice < 1) || (choice > 7)) printf("\n[!!] The number %d is an invalid selection.\n\n", choice); else if (choice < 4) { // Otherwise, choice was a game of some sort. if(choice != last_game) { // If the function ptr isn't set if(choice == 1) // then point it at the selected game player.current_game = pick_a_number; else if(choice == 2) player.current_game = dealer_no_match; else player.current_game = find_the_ace; last_game = choice; // and set last_game. } play_the_game(); // Play the game. } else if (choice == 4) show_highscore(); else if (choice == 5) { printf("\nChange user name\n"); printf("Enter your new name: "); input_name(); printf("Your name has been changed.\n\n"); } else if (choice == 6) { printf("\nYour account has been reset with 100 credits.\n\n"); player.credits = 100; } } update_player_data(); printf("\nThanks for playing! Bye.\n"); }
void game_over_init() { int high_dummy; read_highscore(); if(current_score && (high_dummy = addto_highscore((char *)getenv("USER"),current_score,current_level,current_lines))) { write_highscore(); show_highscore(high_dummy); } game_over = TRUE; game_play = FALSE; gdk_draw_rectangle(game_area->window, game_area->style->black_gc, TRUE, 0,0, game_area->allocation.width, game_area->allocation.height); gdk_draw_rectangle(next_block_area->window, next_block_area->style->black_gc, TRUE, 0,0, next_block_area->allocation.width, next_block_area->allocation.height); game_set_pause(GTK_WIDGET(menu_game_pause),NULL); gtk_label_set(GTK_LABEL(Start_stop_button_label),start_stop_str[0]); gtk_widget_set_sensitive(menu_game_quick,TRUE); gtk_widget_set_sensitive(menu_game_start,TRUE); gtk_widget_set_sensitive(menu_game_stop,FALSE); gtk_widget_set_sensitive(Start_stop_button,TRUE); gtk_widget_grab_default(Start_stop_button); gtk_label_set(GTK_LABEL(Pause_button_label),pause_str[0]); gtk_widget_set_sensitive(Pause_button,FALSE); gtk_timeout_remove(timer); }
void show_highscore_wrapper(GtkMenuItem *menuitem, gpointer user_data) { read_highscore(); show_highscore(0); }