24 FILE* cfgFile = fopen(
"./game.cfg",
"r");
35 FILE* cfgFile = fopen(
"./game.cfg",
"r");
37 while(feof(cfgFile) == 0) {
40 char* _ = fgets(line, 128, cfgFile);
48 char* settingName =
substring(line, 0, equalPosition);
49 char* settingValue =
substring(line, equalPosition + 1, strlen(line) - equalPosition - 1);
51 if(settingValue[strlen(settingValue) - 1] ==
'\n')
52 settingValue[strlen(settingValue) - 1] =
'\0';
54 if(strcmp(
"useTui", settingName) == 0)
55 cfg.
useTui = strcmp(
"true", settingValue) == 0;
56 if(strcmp(
"beVerbose", settingName) == 0)
57 cfg.
beVerbose = strcmp(
"true", settingValue) == 0;
58 else if(strcmp(
"allowSameRank", settingName) == 0)
60 else if(strcmp(
"allowSameSuit", settingName) == 0)
62 else if(strcmp(
"defaultPlayersLPs", settingName) == 0) {
63 const int rs = strtol(settingValue, &endptr, 10);
65 if(errno == ERANGE || *endptr !=
'\0')
69 }
else if(strcmp(
"defaultLPsOnField", settingName) == 0) {
70 const int rs = strtol(settingValue, &endptr, 10);
72 if(errno == ERANGE || *endptr !=
'\0')
93 FILE* cfgFile = fopen(
"game.cfg",
"w+");
95 fprintf(cfgFile,
"useTui=%s\n", configuration.
useTui ?
"true" :
"false");
96 fprintf(cfgFile,
"beVerbose=%s\n", configuration.
beVerbose ?
"true" :
"false");
97 fprintf(cfgFile,
"allowSameRank=%s\n", configuration.
allowSameRank ?
"true" :
"false");
98 fprintf(cfgFile,
"allowSameSuit=%s\n", configuration.
allowSameSuit ?
"true" :
"false");
bool existsConfigurationFile()
Checks by filename if a game configuration file exists.
void saveConfigurationToFile(GameConfiguration configuration, bool overwriteIfExists)
Save the given configuration to the game configuration file. It overwrites an existing file if and on...
GameConfiguration getConfigurationFromFile()
Load the game configuration from the file. It checks if the file exists.
Definition of functions which handles the configuration file.
GameConfiguration getDefaultConfiguration()
Retrieves the default game configuration.
The game configuration structure.
bool allowSameRank
Determines if a player can have cards with the same rank. It increases randomness if set to false.
bool useTui
Determines if the gama has to use the terminal user interface (TUI).
int defaultLPsOnField
The default amount of LPs on the playing field at the beginning of a match.
bool beVerbose
Determines if the program has to have a verbose logging behaviour.
int defaultPlayersLPs
The default amount of LPs that every player have at the beginning of a match.
bool allowSameSuit
Determines if a player can have cards with the same suit It increases randomness if set to false.
bool containsFrom(const char *string, char character, int startPosition)
Checks if there is an occoruncy of the passed char from the passed position in the passed string.
int offsetFromNext(const char *string, char character, int startPosition)
Counts the offset in the string between the position and the next occoruncy of the passed char.
char * substring(const char *string, int startPosition, int length)
Copies a substring (heap-allocated) from the passed string. If fails when allocating memory for the s...