TheCOSCGameProject  1.0
Macros | Functions
toolkit.cpp File Reference

Implements utility functions for the Valeris game. More...

#include "../lib/toolkit.h"
#include "../lib/dependencies.h"
Include dependency graph for toolkit.cpp:

Macros

#define NOMINMAX
 

Functions

void SetTerminalSize (int height, int width)
 Sets the terminal window size on non-Windows systems. More...
 
void delay (int milliseconds)
 Creates a delay for a specified amount of time. More...
 
void disableInput ()
 Disables user input on the console/terminal. More...
 
void enableInput ()
 Enables user input on the console/terminal. More...
 
void typePrint (const std::string &content, int delayTime, const std::string &color)
 Prints text with a typing effect. More...
 
std::string getFileContent (std::string fileName)
 Reads the content of a file into a string. More...
 
std::vector< std::string > split (const std::string &str, char delimiter)
 Splits a string into tokens based on a delimiter. More...
 
void clear (int limit)
 Clears a specified number of lines from the console/terminal. More...
 
std::string getUserInputLine ()
 Gets a full line of user input from the console. More...
 
std::string getUserInputToken ()
 Gets a single word or token of user input from the console. More...
 
int generateRandomNumber (int low, int high)
 Generates a random number within a specified range. More...
 
int stringToInt (const std::string &str)
 Converts a string to an integer. More...
 
std::string repeatString (const std::string &str, int count)
 Repeats a string a specified number of times. More...
 
std::string toLowerCase (const std::string &str)
 Converts a string to lowercase. More...
 
int readInt ()
 Reads an integer from user input. More...
 
void waitForEnter ()
 Waits for the user to press Enter. More...
 
std::string toUpperCase (const std::string &input)
 Converts a string to uppercase. More...
 
std::vector< int > getDist (std::vector< std::string > vector)
 

Detailed Description

Implements utility functions for the Valeris game.

This file contains various utility functions used throughout the Valeris game, including console/terminal manipulation, input handling, string processing, and delays.

Macro Definition Documentation

◆ NOMINMAX

#define NOMINMAX

Function Documentation

◆ clear()

void clear ( int  limit)

Clears a specified number of lines from the console/terminal.

Clear the console up to a certain limit.

Parameters
limitThe number of lines to clear.

This function moves the cursor up and clears the specified number of lines from the console or terminal output.

◆ delay()

void delay ( int  milliseconds)

Creates a delay for a specified amount of time.

Mimic a delay in milliseconds.

Parameters
millisecondsThe number of milliseconds to delay.

This function uses a busy-wait loop to create a delay, which can be used to control the timing of text display or other actions.

◆ disableInput()

void disableInput ( )

Disables user input on the console/terminal.

Disable user input.

Disables input features such as echo and canonical mode on both Windows and non-Windows systems.

◆ enableInput()

void enableInput ( )

Enables user input on the console/terminal.

Enable user input.

Restores input features such as echo and canonical mode on both Windows and non-Windows systems.

◆ generateRandomNumber()

int generateRandomNumber ( int  low,
int  high 
)

Generates a random number within a specified range.

Generate a random number between two values.

Parameters
lowThe lower bound of the range.
highThe upper bound of the range.
Returns
A randomly generated integer within the specified range.

◆ getDist()

std::vector<int> getDist ( std::vector< std::string >  vector)

◆ getFileContent()

std::string getFileContent ( std::string  fileName)

Reads the content of a file into a string.

Read the content of a file and return it as a string.

Parameters
fileNameThe name of the file to read.
Returns
A string containing the contents of the file.

◆ getUserInputLine()

std::string getUserInputLine ( )

Gets a full line of user input from the console.

Get a full line of user input.

Returns
A string containing the user's input.

◆ getUserInputToken()

std::string getUserInputToken ( )

Gets a single word or token of user input from the console.

Get a single word or token of user input.

Returns
A string containing the user's input.

◆ readInt()

int readInt ( )

Reads an integer from user input.

Read an integer from user input.

Returns
The integer value entered by the user.

This function ensures that the input is a valid integer, handling errors and prompting the user until a valid input is received.

◆ repeatString()

std::string repeatString ( const std::string &  str,
int  count 
)

Repeats a string a specified number of times.

Repeat a string a specified number of times.

Parameters
strThe string to repeat.
countThe number of times to repeat the string.
Returns
A string containing the repeated sequence.

◆ SetTerminalSize()

void SetTerminalSize ( int  height,
int  width 
)

Sets the terminal window size on non-Windows systems.

Set the terminal size on non-Windows systems.

Parameters
heightThe desired height of the terminal window.
widthThe desired width of the terminal window.

◆ split()

std::vector<std::string> split ( const std::string &  str,
char  delimiter 
)

Splits a string into tokens based on a delimiter.

Split a string by a delimiter.

Parameters
strThe string to split.
delimiterThe character used as the delimiter.
Returns
A vector of strings representing the tokens.

◆ stringToInt()

int stringToInt ( const std::string &  str)

Converts a string to an integer.

Convert a string to an integer.

Parameters
strThe string to convert.
Returns
The integer value of the string, or 0 if the conversion fails.

◆ toLowerCase()

std::string toLowerCase ( const std::string &  str)

Converts a string to lowercase.

Convert a string to lowercase.

Parameters
strThe string to convert.
Returns
The lowercase version of the string.

◆ toUpperCase()

std::string toUpperCase ( const std::string &  input)

Converts a string to uppercase.

Convert a string to uppercase.

Parameters
inputThe string to convert.
Returns
The uppercase version of the string.

◆ typePrint()

void typePrint ( const std::string &  content,
int  delayTime,
const std::string &  color 
)

Prints text with a typing effect.

Print text with a typing effect.

Parameters
contentThe text content to print.
delayTimeThe delay between each character in milliseconds. Default is 15 milliseconds.
colorThe color code for the text. Default is cyan ("\033[36m").

This function prints text one character at a time, simulating a typing effect, with customizable delay and color.

◆ waitForEnter()

void waitForEnter ( )

Waits for the user to press Enter.

Wait for the user to press Enter.

This function pauses the program and waits for the user to press the Enter key before continuing.