Пример #1
0
int main()
{
	init_curses();

	const char *exit_msg = "";
	srandom(time(NULL));

	struct game_t game = {0};
	int last_turn = game.turns;

	get_highscore_filepath(&game);
	load_highscore(&game);

	place_tile(&game);
	place_tile(&game);

	while (1) {
		print_game(&game);

		if (lose_game(game)) {
			exit_msg = "lost";
			goto lose;
		}

		last_turn = game.turns;

		switch (getch()) {
    case 'h': case KEY_LEFT:  case 'a': move_left(&game); break;
    case 'j': case KEY_DOWN:  case 's': move_down(&game); break;
    case 'k': case KEY_UP:    case 'w': move_up(&game);   break;
    case 'l': case KEY_RIGHT: case 'd': move_right(&game);break;
		case 'q':
			exit_msg = "quit";
			goto end;
		}

		if (last_turn != game.turns)
			place_tile(&game);
	}

lose:
	move(7, 0);
	printw("You lose! Press q to quit.");
	while (getch() != 'q');
end:
	endwin();
	if(game.score > game.highscore)
	{
		game.highscore = game.score;
		save_highscore(&game);
	}
	printf("You %s after scoring %d points in %d turns, "
		"with largest tile %d. The local highscore is %d points.\n",
		exit_msg, game.score, game.turns,
		1 << max_tile((tile_t *)game.board), game.highscore);
	free(game.highscorefile);
	return 0;
}
Пример #2
0
int main()
{
  char key;

  largeur=21;
  hauteur=7;
  tableau = (int*) malloc(largeur*hauteur*sizeof(int));
  vaisseau=')';// D)]#->??*

  load_highscore();
  init_curses();
  srand((unsigned int) time(NULL));
  
  anim_debut();

  help();

  /* Boucle principale, menu */
  do {
    key=wgetch(menubar);
    switch(key)
      {
      case 'n':
        partie();
        break;
      case 's':
        view_highscores();
        break;
      case 'a':
        help();
        break;
      case 'q':
        end_curses();
        return 0;
      }
  } while (1);
    
}
Пример #3
0
/* main()
 * Program entry point. Initializes everything and runs the main loop.
 * Times are calculated and the frame rate is controlled here.
 */
int main( int argc, char* argv[] )
{
	program_state_t* PS  = &program_state;
	game_state_t*    GS  = &game_state;
	sounds_t*      	 snd = &(GS->sounds);

	PS->program_start_us = get_time();

	init_sdl( PS, GS );     // Create window, load sounds
	init_sound( PS, GS );   // Load music, sounds, set volume
	init_font( PS );        // Load font
	init_opengl( PS );      // Load textures

	play_music( snd->music );

	load_highscore( GS );

	PS->current_time_us    =
	PS->frame_start_us     = get_time();

	// Make the following look nice in debug info
	PS->game_start_us      =
	PS->pause_since_us     = PS->program_start_us - 1;

	PS->tick_fraction_s    = -1;

	PS->highest_frame_time = 0;
	PS->lowest_frame_time  = 99999999;

	PS->run_mode = RM_INTRO;

	while (PS->run_mode != RM_EXIT) {

		PS->current_time_us = get_time();

		// Calculate how much time we need to waste for target FPS
		PS->delay_until_us
			= PS->current_time_us
			+ (1000000 / TARGET_FPS)
		;


		// Keep track of game time (handling pause)
		if ( !(PS->run_mode & (RM_PAUSE | RM_MAIN_MENU)) ) {
			PS->game_time_us
				= PS->current_time_us
				- PS->game_start_us
			;

		}

		// Show intro after main menu idles for a while
		if (PS->run_mode == RM_MAIN_MENU) {
			if (PS->main_menu_since_us
				+ MAIN_MENU_INTRO_SWITCH_TIME < get_time()) {
				PS->run_mode = RM_INTRO;
			}
		}

		// Handle user input
		process_event_queue( PS, GS );

		// Let the universe live for a short moment
		if (PS->run_mode & (RM_RUNNING | RM_AFTER_LIFE)) {
			advance_simulation( PS, GS );
		}

		// Display the current world status as game scene
		draw_frame( PS, GS );

#if LIMIT_FPS
		// Waste time until the next frame needs to be drawn
		while (get_time() < PS->delay_until_us) {
	#if LIMIT_FPS_USING_SDL_DELAY
			SDL_Delay( 1 );
	#endif
		}
#endif
		// Keep track of how many FPS we actually achieved
		PS->frame_time_us   = get_time() - PS->frame_start_us;

		PS->highest_frame_time = max(
			PS->highest_frame_time,
			PS->frame_time_us
		);
		PS->lowest_frame_time = min(
			PS->lowest_frame_time,
			PS->frame_time_us
		);

		PS->frame_start_us  = get_time();
		PS->tick_fraction_s = (real_t)PS->frame_time_us / 1000000.0;

		save_frame_time( PS );   // For average FPS
		PS->average_frame_time = average_frame_time( PS );
	}

	save_highscore( PS, GS );

	glDeleteTextures( 1, &(PS->textures.background) );
	glDeleteTextures( 1, &(PS->textures.digits) );

	Mix_FreeChunk( snd->laser );
	Mix_FreeChunk( snd->hit );
	Mix_FreeChunk( snd->punch );
	Mix_FreeChunk( snd->blast );
	Mix_FreeChunk( snd->denied );
	Mix_FreeChunk( snd->alarm );
	Mix_FreeChunk( snd->blub );

	Mix_FreeChunk( snd->computer_autofire );
	Mix_FreeChunk( snd->computer_doubleshot );
	Mix_FreeChunk( snd->computer_roundshot );
	Mix_FreeChunk( snd->computer_danger );
	Mix_FreeChunk( snd->computer_weaponlost );

	Mix_FreeMusic( snd->music );

	SDL_Quit();   // Will (allegedly) also free  screen .

	return 0;
}