Exemplo n.º 1
0
/**	Creates/reads from the High Score file
 *
 * 	First, we try to open for reading. If it doesn't exist, then we
 *  open it for writing, effectively creating it.
 *
 */
void hscore_init ()
{
	FILE* file = fopen (SCORE_PATH, "rb");

	game.cant_open_hscore_file = 0;

	if (file == NULL)
		hscore_clean ();

	else
	{
		int items_read;

		items_read = fread (&HIGH_SCORE_BORDERS, sizeof (int), 1, file);
		if (items_read != 1)
			nsnake_abort ("Highscore File I/O error!\nTry cleaning the scores file!");

		items_read = fread (&HIGH_SCORE_BORDERS_OFF, sizeof (int), 1, file);
		if (items_read != 1)
			nsnake_abort ("Highscore File I/O error!\nTry cleaning the scores file!");
	}

	file = fopen (SCORE_PATH, "rb");
	if (file == NULL)
	{
		//This time it really couldnt open the score file
		game.cant_open_hscore_file = 1;
	}
	else
		fclose (file);
}
Exemplo n.º 2
0
Arquivo: engine.c Projeto: gsrr/Python
/**	Starts the game engine. Initializes all the stuff related to ncurses.
 *
 *  @note If some engine-specific initialization fails, the game aborts.
 */
void engine_init ()
{
	screen.width  = 80;
	screen.height = 24;

	// Starts the ncurses mode
	initscr ();

	if (has_colors() == FALSE)
		nsnake_abort ("Your terminal does not support colors.\n");

	// Start support for colors ( Name, Foreground, Background )
	start_color ();
	init_pair (GREEN_BLACK, COLOR_GREEN, COLOR_BLACK);
	init_pair (CYAN_BLACK,  COLOR_CYAN,  COLOR_BLACK);
	init_pair (WHITE_BLACK, COLOR_WHITE, COLOR_BLACK);
	init_pair (RED_BLACK,   COLOR_RED,   COLOR_BLACK);
	init_pair (BLUE_BLACK,  COLOR_BLUE,  COLOR_BLACK);
	init_pair (BLACK_WHITE, COLOR_BLACK, COLOR_WHITE);

	int current_height, current_width;
	// Gets the current width and height of the terminal
	getmaxyx (stdscr, current_height, current_width);

	if ((current_width < screen.width) || (current_height < screen.height))
		nsnake_abort ("Your console screen is smaller than 80x24\n"
		               "Please resize your window and try again\n\n");

	// Character input doesnt require the <enter> key anymore
	raw ();

	// Makes the cursor invisible
	curs_set (0);

	// Support for extra keys (life F1, F2, ... )
	keypad (stdscr, true);

	// Wont print the input received
	noecho ();

	// Wont wait for input - the game will run instantaneously
	nodelay (stdscr, true);

	// Refresh the screen (prints whats in the buffer)
	refresh ();

	game.mode = BORDERS_ON;
}