Sokoban
Public Types | Public Member Functions | Private Attributes | List of all members
HighScore Class Reference

Class which represents highscore database. More...

#include <HighScore.h>

Public Types

enum  result { bad_time, best_user_time, best_map_time }
 Enum which represents types of result for user on map according to the previous time of user. More...
 

Public Member Functions

std::string get_map_best_time (const std::string &map_id)
 Gets string with the best time for map and with the name of user which beats this time. More...
 
std::string get_user_best_time (const std::string &user, const std::string &map_id)
 Gets string with the best user's time for map. More...
 
result set_time (const std::string &user, const std::string &map_id, uint64_t time)
 Set time for user on map. More...
 
void to_stream (std::ofstream &ofs)
 Writes high score database to the stream. More...
 

Private Attributes

std::unordered_map< std::string, std::string > map_highscore
 Unordered map. More...
 
std::unordered_map< std::string, std::unordered_map< std::string, uint64_t > > user_highscore
 Unordered map. More...
 

Detailed Description

Class which represents highscore database.

Member Enumeration Documentation

◆ result

Enum which represents types of result for user on map according to the previous time of user.

Enumerator
bad_time 
best_user_time 

< Current time is worse than the previous.

best_map_time 

< The best time of user.

< The best time for map.

Member Function Documentation

◆ get_map_best_time()

std::string HighScore::get_map_best_time ( const std::string &  map_id)
inline

Gets string with the best time for map and with the name of user which beats this time.

Parameters
map_idIdentifier of map.
Returns
The best time in format hh:mm:ss for map with the name of user which beats this time.

◆ get_user_best_time()

std::string HighScore::get_user_best_time ( const std::string &  user,
const std::string &  map_id 
)
inline

Gets string with the best user's time for map.

Parameters
userName of user.
map_idIdentifier of map.
Returns
The best time of user on map.

◆ set_time()

result HighScore::set_time ( const std::string &  user,
const std::string &  map_id,
uint64_t  time 
)
inline

Set time for user on map.

Time is update if it is better than previous.

Parameters
userName of user.
map_idIdentifier of map.
timeTime of user on map.
See also
result TODO
Returns
Enum which represents if the best time was beaten and how.

◆ to_stream()

void HighScore::to_stream ( std::ofstream &  ofs)
inline

Writes high score database to the stream.

Parameters
ofsStream which is highscore writen to.

Member Data Documentation

◆ map_highscore

std::unordered_map<std::string, std::string> HighScore::map_highscore
private

Unordered map.

Represents high score for map, for each map there is name of user which has the best time.

◆ user_highscore

std::unordered_map<std::string, std::unordered_map<std::string, uint64_t> > HighScore::user_highscore
private

Unordered map.

represents high score for user, for each user there is a unordered map with map and best time


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