nSnake
A ncurses implementation of the classic Snake game
Data Structures | Functions | Variables
src/engine.h File Reference

Declaration of the graphical engine functions, defines and globals. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  screen_t
 Global definitions related to the game screen. More...

Functions

void draw_background ()
 Just erases everything to black.
void draw_borders ()
 Draws the window border, according to the game.mode.
void draw_fruit ()
 Draws the current fruit on screen.
void draw_fruit_bonus ()
 Draws the bonus value of the current fruit.
void draw_player ()
 Draws the snake - from the head to the whole body.
void draw_score ()
 Prints the current score.
void engine_exit ()
 Exits and dealocates the memory required by ncurses.
void engine_init ()
 Starts the game engine.
void engine_show_game_over ()
 Draws the Game Over screen.
void engine_show_main_menu ()
 Displays the main menu and gets the user input from it.
void engine_show_pause ()
 Prints the pause message.
void engine_show_screen ()
 Completely draws the screen during game.
int get_main_menu_input (int *current_option)
 Gets the input for the main menu.
void engine_get_game_input ()
 Get the user input during game and make the right decisions.
void get_game_over_input ()
 Waits for an user action during the 'Game Over' screen.
void get_pause_input ()
 Just waits untill the user either unpauses the game or exits.
void start_atrribute (int attr)
 Wrapper to the attron() function, in case the current terminal doesn't support colors.

Variables

struct screen_t screen
 Global screen structure.

Detailed Description

Declaration of the graphical engine functions, defines and globals.


Function Documentation

void engine_init ( )

Starts the game engine.

Initializes all the stuff related to ncurses.

Note:
If some engine-specific initialization fails, the game aborts.
Todo:
There must have a game init function or something where i could put this

Draws the Game Over screen.

Besides drawing 'Game Over', it highlights where the player died.

Displays the main menu and gets the user input from it.

This function blocks the game execution and waits for user input, refreshing the main menu screen according to the options selected.

Completely draws the screen during game.

The usleep() function interrupts the program for 'n' microseconds. It was difficult to get a stable value for the game progression.

Note:
This is the main function of this file because it shows logically how the process of drawing the screen sould be
 All Data Structures Files Functions Variables Enumerations Defines