Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
tui.h
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
23
24#include "ansi.h"
25#include "main.h"
26#include "consts.h"
27#include "ansi_const.h"
28
29#ifndef _GUI_H_
31 #define _GUI_H_
32
34 #define CARD_WIDTH 15
36 #define CARD_HEIGHT 9
38 #define LOG_SECTION_HEIGHT 4
40 #define MIN_ROWS ((2 * (CARD_HEIGHT + 4)) + (LOG_SECTION_HEIGHT + 2))
42 #define MIN_COLUMNS 141
43
57
65 void drawCardsForPage(PageData* page, int startX, int bestStartColumn);
66
73 void drawPageFrame(int maxRows, int maxColumns);
74
83 void displayPage(PageData* page, int maxRows, int maxColumns, int bestStartColumn);
84
96 void navigatePages(PageData* pagesData, int totalPages, int maxRows, int maxColumns, int bestStartColumn, int playerIndex, Game* game);
97
104 int getCardColor(int cardRank);
105
115 void drawLine(int startingX, int startingY, int length, char direction, char borders);
116
125 void drawCard(int startingX, int startingY, int suit, int rank);
126
138 PageData* getPageData(int maxRows, int maxColumns, Player** players, int totalPlayers, int* totalPages, int* bestStartColumn);
139
146 void freePageData(PageData* pages, int totalPages);
147
155 bool isTerminalSizeValid(int maxRows, int maxColumns);
156
165 int getPageContainingPlayer(PageData* pagesData, int totalPages, int id);
166
167#endif
Implemented following https://en.wikipedia.org/wiki/ANSI_escape_code.
Declaration of constant values for ANSI module.
Declaration of constants used by the modules.
Declaration of game-related constants, definition of game-related structures and functions.
Defines a structure for the game.
Definition main.h:80
Struct to represent the layout and data of a page containing player information.
Definition tui.h:45
int playerPerRow
The number of players displayed per row.
Definition tui.h:49
int playerRows
The number of rows used to display players on the page.
Definition tui.h:47
int playerCount
The total number of players on the page.
Definition tui.h:51
Player ** players
An array of pointers to the players displayed on the page.
Definition tui.h:55
int rowSpacing
The vertical spacing between rows, including card height and player details.
Definition tui.h:53
Defines a structure for the player's info.
Definition main.h:66
void drawPageFrame(int maxRows, int maxColumns)
Draws the frame for a page, including borders and separators.
Definition tui.c:114
int getPageContainingPlayer(PageData *pagesData, int totalPages, int id)
Determines which page contains a player by their ID.
Definition tui.c:287
PageData * getPageData(int maxRows, int maxColumns, Player **players, int totalPlayers, int *totalPages, int *bestStartColumn)
Computes the page layout for players and allocates memory for the page data.
Definition tui.c:223
void drawCard(int startingX, int startingY, int suit, int rank)
Draws a card at a specified position.
Definition tui.c:182
void freePageData(PageData *pages, int totalPages)
Frees the memory allocated for page data.
Definition tui.c:276
void drawLine(int startingX, int startingY, int length, char direction, char borders)
Draws a line in the terminal.
Definition tui.c:150
int getCardColor(int cardRank)
Retrieves the color associated with a card rank.
Definition tui.c:206
void displayPage(PageData *page, int maxRows, int maxColumns, int bestStartColumn)
Displays a page of cards and player information.
Definition tui.c:108
void drawCardsForPage(PageData *page, int startX, int bestStartColumn)
Draws all cards for the current page.
Definition tui.c:129
bool isTerminalSizeValid(int maxRows, int maxColumns)
Checks if the terminal size meets the minimum requirements.
Definition tui.c:283
void navigatePages(PageData *pagesData, int totalPages, int maxRows, int maxColumns, int bestStartColumn, int playerIndex, Game *game)
Navigates between pages and handles player actions during their turn.
Definition tui.c:32