Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1// Copyright (C) 2025 Giulio Salvi, Jacopo Paradisi
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
20
21#include "config.h"
22
24 const GameConfiguration cfg = {
25 .useTui = true,
26 .beVerbose = false,
27 .allowSameRank = true,
28 .allowSameSuit = true,
29 .defaultLPsOnField = 0,
30 .defaultPlayersLPs = 2
31 };
32
33 return cfg;
34}
35
38 return config.useTui == d.useTui &&
39 config.beVerbose == d.beVerbose &&
40 config.allowSameRank == d.allowSameRank &&
41 config.allowSameSuit == d.allowSameSuit &&
44}
45
46GameConfiguration getGameConfiguration(const int code, const GameConfiguration cliGameConfiguration) {
47 if(code == ACTION_HELP)
48 exit(EXIT_SUCCESS);
49
51 bool ignoreConfigFile = code & 0b00001;
52 bool dontAskConfigOptions = code & 0b00010;
53 bool saveToFile = code & 0b00100;
54 bool beVerbose = code & 0b01000;
55 bool useTui = code & 0b10000;
56
57 if(!ignoreConfigFile && existsConfigurationFile())
59 else if(!isDefaultGameConfiguration(cliGameConfiguration))
60 cfg = cliGameConfiguration;
61 else if(!dontAskConfigOptions)
63 else
65
66 cfg.useTui = useTui;
67 cfg.beVerbose = beVerbose;
68
69 if(saveToFile)
70 saveConfigurationToFile(cfg, true);
71
72 return cfg;
73}
GameConfiguration getDefaultConfiguration()
Retrieves the default game configuration.
Definition config.c:23
GameConfiguration getGameConfiguration(const int code, const GameConfiguration cliGameConfiguration)
Gets the game configuration based on the action code. If action code is ACTION_HELP,...
Definition config.c:46
bool isDefaultGameConfiguration(const GameConfiguration config)
Determines if a given game configuration is the default one.
Definition config.c:36
Definition of functions which retrieves the game configuration from the possible sources.
GameConfiguration askConfigurationOptionsViaTerminal()
Asks to the user via terminal the game configuration.
Definition main.c:148
bool existsConfigurationFile()
Checks by filename if a game configuration file exists.
Definition config_file.c:23
void saveConfigurationToFile(GameConfiguration configuration, bool overwriteIfExists)
Save the given configuration to the game configuration file. It overwrites an existing file if and on...
Definition config_file.c:89
GameConfiguration getConfigurationFromFile()
Load the game configuration from the file. It checks if the file exists.
Definition config_file.c:33
#define ACTION_HELP
With this action code, the program has printed help messages.
Definition consts.h:49
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.