28 struct tm* ltm = localtime(&(time_t){time(NULL)});
31 ltm->tm_mday, ltm->tm_mon + 1, ltm->tm_year + 1900,
32 ltm->tm_hour, ltm->tm_min, ltm->tm_sec
37 printfgr(
"#b##%d#Failed to create a log file, the console is going to be used.#r#\n",
FgBrightRed);
38 return logsConfiguration;
41 FILE* logsFile = fopen(logsConfiguration.
fileName,
"a+");
42 if(logsFile == NULL) {
44 printfgr(
"#b##%d#Failed to create a log file, the console is going to be used.#r#\n",
FgBrightRed);
50 return logsConfiguration;
54 FILE* outStream = !logsConfiguration.
useConsole ? fopen(logsConfiguration.
fileName,
"a+") : stdout;
56 fprintf(outStream,
"Allow cards with the same rank: ");
58 fprintf(outStream,
"true");
60 fprintf(outStream,
"false");
62 fprintf(outStream,
", allow cards with the same suit: ");
64 fprintf(outStream,
"true");
66 fprintf(outStream,
"false");
70 fprintf(outStream, !logsConfiguration.
useConsole || newLine ?
"\n" :
"");
86 printgr(
"#r# faced up and #b#");
93 FILE* logFile = fopen(logsConfiguration.
fileName,
"a+");
95 fprintf(logFile,
"Player %d with %d LPs has cards ", player.
id, player.
lifePoints);
100 logFile = fopen(logsConfiguration.
fileName,
"a+");
101 fprintf(logFile,
" faced up and ");
106 logFile = fopen(logsConfiguration.
fileName,
"a+");
107 fprintf(logFile,
" faced down.\n%s", newLine ?
"\n" :
"");
113 FILE* outStream = !logsConfiguration.
useConsole ? fopen(logsConfiguration.
fileName,
"a+") : stdout;
117 fprintf(outStream,
"Clubs");
120 fprintf(outStream,
"Spades");
123 fprintf(outStream,
"Diamonds");
126 fprintf(outStream,
"Hearts");
130 fprintf(outStream,
" ");
134 fprintf(outStream,
"Ace");
137 fprintf(outStream,
"Two");
140 fprintf(outStream,
"Three");
143 fprintf(outStream,
"Four");
146 fprintf(outStream,
"Five");
149 fprintf(outStream,
"Six");
152 fprintf(outStream,
"Seven");
155 fprintf(outStream,
"Jack");
158 fprintf(outStream,
"Queen");
161 fprintf(outStream,
"King");
165 fprintf(outStream, newLine ?
"\n" :
"");
173 for(
int i = 0; i < 40; i++)
174 printCard(deck[i], logsConfiguration, i == 39 ? newLine :
true);
178 FILE* outStream = !logsConfiguration.
useConsole ? fopen(logsConfiguration.
fileName,
"a+") : stdout;
180 for (
int i = 0; i < totalPages; i++) {
181 fprintf(outStream,
"Page %d:\n", i + 1);
182 fprintf(outStream,
" Rows: %d, Players Per Row: %d, Total Players: %d\n",
183 pages[i].playerRows, pages[i].playerPerRow, pages[i].playerCount);
186 fprintf(outStream,
" Player ID: %d, Life Points: %d\n",
187 pages[i].players[j]->
id,
188 pages[i].players[j]->lifePoints);
190 fprintf(outStream,
"\n");
193 fprintf(outStream, !logsConfiguration.
useConsole || newLine ?
"\n" :
"");
Implemented following https://en.wikipedia.org/wiki/ANSI_escape_code.
void printgr(const char *text)
Prints a text with the graphic rendition specified with custom graphic rendition format specifiers.
void printfgr(char *text,...)
Prints text as printgr but handles standard C format specifiers %, d, i, u, x, X, f,...
Declaration of constant values for ANSI module.
#define FgBrightRed
ANSI standard bright red foreground color.
void printGameConfiguration(GameConfiguration configuration, LogsConfiguration logsConfiguration, bool newLine)
Prints user-friendly game configuration settings.
void printPlayer(Player player, LogsConfiguration logsConfiguration, bool newLine)
Prints user-friendly player's info.
void printPlayers(Game game, bool newLine)
Prints user-friendly the players' infos.
void printDeck(Card *deck, LogsConfiguration logsConfiguration, bool newLine)
Prints user-friendly the cards deck.
void printPageData(PageData pages[], LogsConfiguration logsConfiguration, int totalPages, bool newLine)
Prints user-friendly the pages' infos.
void printCard(Card card, LogsConfiguration logsConfiguration, bool newLine)
Prints user-friendly the card rank and suit.
LogsConfiguration prepareLogs()
Generates the logger configuration for the current session. Tries to generate the log file.
Definition of logger functions.
#define fileNameBufferSize
The length of the string "logs/dd-MM-yyyy_hh,mm,ss.log", that is the pattern of the filename of every...
#define Diamonds
Integer const to represent suit diamonds.
#define Five
Integer const to represent rank five.
#define Spades
Integer const to represent suit spades.
#define Seven
Integer const to represent rank seven.
#define Three
Integer const to represent rank three.
#define Jack
Integer const to represent rank jack.
#define Four
Integer const to represent rank four.
#define Ace
Integer const to represent rank ace.
#define Clubs
Integer const to represent suit clubs.
#define Hearts
Integer const to represent suit hearts.
#define Six
Integer const to represent rank six.
#define Queen
Integer const to represent rank queen.
#define King
Integer const to represent rank king.
#define Two
Integer const to represent rank two.
Defines a structure for the cards.
unsigned int rank
The rank of the card.
unsigned int suit
The suit of the card.
The game configuration structure.
bool allowSameRank
Determines if a player can have cards with the same rank. It increases randomness if set to false.
int defaultLPsOnField
The default amount of LPs on the playing field at the beginning of a match.
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.
Defines a structure for the game.
unsigned int playersCounter
The amount of players currently alive.
Player ** players
The currently alive players vector.
LogsConfiguration logsConfiguration
The configuration for the logs, if the game has to be verbose.
The configuration for the logger.
char fileName[fileNameBufferSize]
The filename path to the log file used in a session. It can be a valid path or an empty string if the...
bool useConsole
Flag for the logger to determine if it has to use the console or the log file.
Struct to represent the layout and data of a page containing player information.
int playerCount
The total number of players on the page.
Defines a structure for the player's info.
Card facedDownCard
The faced down card.
unsigned int lifePoints
The current player LPs.
unsigned int id
The player ID.
Card facedUpCard
The faced up card.
Terminal User Interface (TUI) implementation for card game display.