Survival Royale 1.0.0
A very simple yet funny card game.
Loading...
Searching...
No Matches
tui.h File Reference

Terminal User Interface (TUI) implementation for card game display. More...

#include "ansi.h"
#include "main.h"
#include "consts.h"
#include "ansi_const.h"

Go to the source code of this file.

Data Structures

struct  PageData
 Struct to represent the layout and data of a page containing player information. More...

Macros

#define _GUI_H_
 Include guard.
#define CARD_WIDTH   15
 Integer const to represent the width of a card.
#define CARD_HEIGHT   9
 Integer const to represent the height of a card.
#define LOG_SECTION_HEIGHT   4
 Integer const to represent the height of the logs section.
#define MIN_ROWS   ((2 * (CARD_HEIGHT + 4)) + (LOG_SECTION_HEIGHT + 2))
 Integer const to represent the minimum rows of the terminal in order to start the game.
#define MIN_COLUMNS   141
 Integer const to represent the minimum columns of the terminal in order to start the game.

Typedefs

typedef struct PageData PageData
 Struct to represent the layout and data of a page containing player information.

Functions

void drawCardsForPage (PageData *page, int startX, int bestStartColumn)
 Draws all cards for the current page.
void drawPageFrame (int maxRows, int maxColumns)
 Draws the frame for a page, including borders and separators.
void displayPage (PageData *page, int maxRows, int maxColumns, int bestStartColumn)
 Displays a page of cards and player information.
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.
int getCardColor (int cardRank)
 Retrieves the color associated with a card rank.
void drawLine (int startingX, int startingY, int length, char direction, char borders)
 Draws a line in the terminal.
void drawCard (int startingX, int startingY, int suit, int rank)
 Draws a card at a specified position.
PageDatagetPageData (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.
void freePageData (PageData *pages, int totalPages)
 Frees the memory allocated for page data.
bool isTerminalSizeValid (int maxRows, int maxColumns)
 Checks if the terminal size meets the minimum requirements.
int getPageContainingPlayer (PageData *pagesData, int totalPages, int id)
 Determines which page contains a player by their ID.

Detailed Description

Terminal User Interface (TUI) implementation for card game display.

This file contains functions to handle terminal-based user interface components, including drawing cards, player information, and navigation between pages.

Definition in file tui.h.

Macro Definition Documentation

◆ _GUI_H_

#define _GUI_H_

Include guard.

Definition at line 31 of file tui.h.

◆ CARD_HEIGHT

#define CARD_HEIGHT   9

Integer const to represent the height of a card.

Definition at line 36 of file tui.h.

◆ CARD_WIDTH

#define CARD_WIDTH   15

Integer const to represent the width of a card.

Definition at line 34 of file tui.h.

◆ LOG_SECTION_HEIGHT

#define LOG_SECTION_HEIGHT   4

Integer const to represent the height of the logs section.

Definition at line 38 of file tui.h.

◆ MIN_COLUMNS

#define MIN_COLUMNS   141

Integer const to represent the minimum columns of the terminal in order to start the game.

Definition at line 42 of file tui.h.

◆ MIN_ROWS

#define MIN_ROWS   ((2 * (CARD_HEIGHT + 4)) + (LOG_SECTION_HEIGHT + 2))

Integer const to represent the minimum rows of the terminal in order to start the game.

Definition at line 40 of file tui.h.

Typedef Documentation

◆ PageData

typedef struct PageData PageData

Struct to represent the layout and data of a page containing player information.

Function Documentation

◆ displayPage()

void displayPage ( PageData * page,
int maxRows,
int maxColumns,
int bestStartColumn )

Displays a page of cards and player information.

Parameters
pageThe page data to display.
maxRowsThe maximum number of terminal rows.
maxColumnsThe maximum number of terminal columns.
bestStartColumnThe best column position to center the content.

Definition at line 108 of file tui.c.

◆ drawCard()

void drawCard ( int startingX,
int startingY,
int suit,
int rank )

Draws a card at a specified position.

Parameters
startingXThe row position to start drawing.
startingYThe column position to start drawing.
suitThe card suit (e.g., Clubs, Spades).
rankThe card rank (e.g., Ace, Two).

Definition at line 182 of file tui.c.

◆ drawCardsForPage()

void drawCardsForPage ( PageData * page,
int startX,
int bestStartColumn )

Draws all cards for the current page.

Parameters
pageThe page data containing player information.
startXThe starting row for drawing.
bestStartColumnThe best column position to center the content.

Definition at line 129 of file tui.c.

◆ drawLine()

void drawLine ( int startingX,
int startingY,
int length,
char direction,
char borders )

Draws a line in the terminal.

Parameters
startingXThe starting row position.
startingYThe starting column position.
lengthThe length of the line.
directionThe direction of the line ('h' for horizontal, 'v' for vertical).
bordersThe type of border ('u' for upper, 'd' for lower, 'n' for none).

Definition at line 150 of file tui.c.

◆ drawPageFrame()

void drawPageFrame ( int maxRows,
int maxColumns )

Draws the frame for a page, including borders and separators.

Parameters
maxRowsThe maximum number of terminal rows.
maxColumnsThe maximum number of terminal columns.

Definition at line 114 of file tui.c.

◆ freePageData()

void freePageData ( PageData * pages,
int totalPages )

Frees the memory allocated for page data.

Parameters
pagesPointer to the array of PageData structs to be freed.
totalPagesThe total number of pages to free.

Definition at line 276 of file tui.c.

◆ getCardColor()

int getCardColor ( int cardRank)

Retrieves the color associated with a card rank.

Parameters
cardRankThe rank of the card.
Returns
A string representing the terminal color code.

Definition at line 206 of file tui.c.

◆ getPageContainingPlayer()

int getPageContainingPlayer ( PageData * pagesData,
int totalPages,
int id )

Determines which page contains a player by their ID.

Parameters
pagesDataThe data of all pages.
totalPagesThe total number of pages.
idThe ID of the player to locate.
Returns
The index of the page containing the player, or -1 if not found.

Definition at line 287 of file tui.c.

◆ getPageData()

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.

Parameters
maxRowsThe maximum number of rows in the terminal.
maxColumnsThe maximum number of columns in the terminal.
playersAn array of pointers to all players.
totalPlayersThe total number of players in the game.
totalPagesPointer to store the total number of pages.
bestStartColumnPointer to store the starting column for centering the cards.
Returns
Pointer to the array of PageData structs representing the pages.

Definition at line 223 of file tui.c.

◆ isTerminalSizeValid()

bool isTerminalSizeValid ( int maxRows,
int maxColumns )

Checks if the terminal size meets the minimum requirements.

Parameters
maxRowsThe number of terminal rows.
maxColumnsThe number of terminal columns.
Returns
True if the terminal size is valid, false otherwise.

Definition at line 283 of file tui.c.

◆ navigatePages()

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.

Parameters
pagesDataThe data of all pages.
totalPagesThe total number of pages.
maxRowsThe maximum number of rows in the terminal.
maxColumnsThe maximum number of columns in the terminal.
bestStartColumnThe starting column to align content.
playerIndexThe index of the current player.
gamePointer to the game state.

Definition at line 32 of file tui.c.