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

Implementation of TUI functions. More...

#include "tui.h"

Go to the source code of this file.

Functions

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.
void displayPage (PageData *page, int maxRows, int maxColumns, int bestStartColumn)
 Displays a page of cards and player information.
void drawPageFrame (int maxRows, int maxColumns)
 Draws the frame for a page, including borders and separators.
void drawCardsForPage (PageData *page, int startX, int bestStartColumn)
 Draws all cards for the current page.
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.
int getCardColor (int cardRank)
 Retrieves the color associated with a card rank.
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.

Variables

const char * CARD_RANK_STRINGS []
const char * CARD_SUIT_STRINGS []

Detailed Description

Implementation of TUI functions.

Definition in file tui.c.

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.

Variable Documentation

◆ CARD_RANK_STRINGS

const char* CARD_RANK_STRINGS[]
Initial value:
= {
"Ace", "Two", "Three", "Four", "Five",
"Six", "Seven", "Jack", "Queen", "King"
}

Definition at line 23 of file tui.c.

◆ CARD_SUIT_STRINGS

const char* CARD_SUIT_STRINGS[]
Initial value:
= {
"Clubs", "Spades", "Diamonds", "Hearts"
}

Definition at line 28 of file tui.c.