nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
ScoreFile Class Reference

Stores points the player made on the game. More...

#include <ScoreFile.hpp>

Collaboration diagram for ScoreFile:

Public Member Functions

 ScoreFile (std::string levelName)
 Creates a new score handler for the level #levelName.
 
void load ()
 Loads all high score entries based on a level name.
 
void save ()
 Saves all the current scores on the file.
 
bool handle (ScoreEntry *score)
 Checks if #score is the highest score and make it so.
 

Static Public Member Functions

static void eraseAll ()
 Erases all high score files.
 

Public Attributes

ScoreEntryhighScore
 Maximum high score obtained for the current game.
 

Static Public Attributes

static std::string directory = ""
 Default directory where we store the game score files.
 
static std::string extension = "nsnakescores"
 Default extension to save the score files.
 

Detailed Description

Stores points the player made on the game.

There's different high scores for different game settings.

Each time the user runs the game with a different configuration of the tweaks above, a new high score is generated.

It always starts with 0 and if the player surpasses it, will be the new maximum.

Definition at line 87 of file ScoreFile.hpp.

Constructor & Destructor Documentation

◆ ScoreFile()

ScoreFile::ScoreFile ( std::string levelName)

Creates a new score handler for the level #levelName.

Note
It doesn't actually work unless you call load, mate

Definition at line 91 of file ScoreFile.cpp.

Member Function Documentation

◆ eraseAll()

void ScoreFile::eraseAll ( )
static

Erases all high score files.

By "all" I mean every single score file from the arcade mode to all levels.

Definition at line 71 of file ScoreFile.cpp.

◆ handle()

bool ScoreFile::handle ( ScoreEntry * score)

Checks if #score is the highest score and make it so.

Call this when you finished the game.

Returns
If #score just became the highest score.

Definition at line 263 of file ScoreFile.cpp.

◆ load()

void ScoreFile::load ( )

Loads all high score entries based on a level name.

The file where we save the high scores will be based on the level name.

Note
If levelName is empty, will fall back to the default score file (see Globals).

Definition at line 96 of file ScoreFile.cpp.

◆ save()

void ScoreFile::save ( )

Saves all the current scores on the file.

Definition at line 202 of file ScoreFile.cpp.

Member Data Documentation

◆ directory

std::string ScoreFile::directory = ""
static

Default directory where we store the game score files.

By default is the same directory as the level files (see BoardParser).

So the default behavior is to create a score file with the same name as the level and a custom extension.

Definition at line 97 of file ScoreFile.hpp.

◆ extension

std::string ScoreFile::extension = "nsnakescores"
static

Default extension to save the score files.

It's all the part that comes after the dot on a file name.

Note
Defaults to "nsnakescores"

Definition at line 105 of file ScoreFile.hpp.

◆ highScore

ScoreEntry* ScoreFile::highScore

Maximum high score obtained for the current game.

It will point to an element within entries that has the highest score for this game settings.

Note
If this is NULL then we couldn't open the high score files!

Definition at line 148 of file ScoreFile.hpp.


The documentation for this class was generated from the following files: