nSnake
A ncurses implementation of the classic Snake game
 All Data Structures Files Functions Variables Enumerations Macros Pages
Functions | Variables
hscores.c File Reference

Definition of the functions related to high scores. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include "hscores.h"
#include "player.h"
Include dependency graph for hscores.c:

Go to the source code of this file.

Functions

int hscore_globals_init ()
 Initializes all global variables needed for high scores. More...
 
int directory_exists (char *path)
 Local function that tests if the directory #path exists. More...
 
int create_directory (char *path)
 Creates a directory on #path. More...
 
int file_exists (char *path)
 Check if a file exists. More...
 
int create_file (char *path)
 Creates a file. More...
 
int hscore_file_check ()
 Tells if the high score file is accessible. More...
 
int hscore_clean ()
 Restore the Highscores to the default. More...
 
void hscore_init ()
 Creates/reads from the High Score file. More...
 
void hscore_store ()
 Records the player High Score.
 

Variables

int HIGH_SCORE_DEFAULT = 500
 The Default HighScore.
 
int HIGH_SCORE_BORDERS = 0
 The separate Highscore for the game mode with borders. More...
 
int HIGH_SCORE_BORDERS_OFF = 0
 The separate Highscore for the game mode without borders. More...
 
char SCORE_DIR [255]
 The directory where we'll keep the highscore file.
 
char SCORE_PATH [255]
 Full absolute path to the highscore file.
 

Detailed Description

Definition of the functions related to high scores.

Definition in file hscores.c.

Function Documentation

int create_directory ( char *  path)

Creates a directory on #path.

Returns
-1 on error, 0 on success.
Note
Creates with permissions 755.

Definition at line 127 of file hscores.c.

int create_file ( char *  path)

Creates a file.

Returns
1 if successful, 0 if failed

Definition at line 157 of file hscores.c.

int directory_exists ( char *  path)

Local function that tests if the directory #path exists.

Note
Must be a null-terminated absolute path.
Returns
1 if directory exists, 0 if it doesn't.

Definition at line 104 of file hscores.c.

int file_exists ( char *  path)

Check if a file exists.

Returns
0 if doesnt exist, 1 if exists

Definition at line 135 of file hscores.c.

int hscore_clean ( )

Restore the Highscores to the default.

Note
If the Highscores file doesn't exist, it is created.

Definition at line 203 of file hscores.c.

int hscore_file_check ( )

Tells if the high score file is accessible.

Returns
0 if success, 1 if failed.

Definition at line 170 of file hscores.c.

int hscore_globals_init ( )

Initializes all global variables needed for high scores.

Note
Can be called multiple times, won't overwrite things.

Definition at line 72 of file hscores.c.

void hscore_init ( )

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.

Note
The path to the score file is defined by the Makefile. Currently, it is /var/games/.nsnake.scores
Todo:
clean this code. Lots of useless ifs and elses.

Definition at line 236 of file hscores.c.

Variable Documentation

int HIGH_SCORE_BORDERS = 0

The separate Highscore for the game mode with borders.

HighScore of the game mode with borders.

Definition at line 58 of file hscores.c.

int HIGH_SCORE_BORDERS_OFF = 0

The separate Highscore for the game mode without borders.

HighScore of the game mode without borders.

Definition at line 61 of file hscores.c.