TheCOSCGameProject  1.0
Functions
toolkit.h File Reference

Utility functions for the Valeris game. More...

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <chrono>
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
Include dependency graph for toolkit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void SetTerminalSize (int height, int width)
 Set the terminal size on non-Windows systems. More...
 
void delay (int milliseconds)
 Mimic a delay in milliseconds. More...
 
void typePrint (const std::string &content, int delayTime=15, const std::string &color="\3[36m")
 Print text with a typing effect. More...
 
std::string getFileContent (std::string fileName)
 Read the content of a file and return it as a string. More...
 
std::vector< std::string > split (const std::string &str, char delimiter)
 Split a string by a delimiter. More...
 
void clear (int limit)
 Clear the console up to a certain limit. More...
 
std::string getUserInputLine ()
 Get a full line of user input. More...
 
std::string getUserInputToken ()
 Get a single word or token of user input. More...
 
int generateRandomNumber (int low, int high)
 Generate a random number between two values. More...
 
int stringToInt (const std::string &str)
 Convert a string to an integer. More...
 
std::string repeatString (const std::string &str, int count)
 Repeat a string a specified number of times. More...
 
std::string toLowerCase (const std::string &str)
 Convert a string to lowercase. More...
 
int readInt ()
 Read an integer from user input. More...
 
void disableInput ()
 Disable user input. More...
 
void enableInput ()
 Enable user input. More...
 
void waitForEnter ()
 Wait for the user to press Enter. More...
 
std::string toUpperCase (const std::string &input)
 Convert a string to uppercase. More...
 
std::vector< int > getDist (std::vector< std::string > vector)
 

Detailed Description

Utility functions for the Valeris game.

This file contains various utility functions that are used throughout the Valeris game. These include functions for console manipulation, input handling, string processing, and more.

Function Documentation

◆ clear()

void clear ( int  limit)

Clear the console up to a certain limit.

Parameters
limitThe number of lines to clear.

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)

Mimic a delay in milliseconds.

Parameters
millisecondsThe number of milliseconds to delay.

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 ( )

Disable user input.

Disable user input.

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

◆ enableInput()

void enableInput ( )

Enable user input.

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 
)

Generate a random number between two values.

Parameters
lowThe lower bound of the random number.
highThe upper bound of the random number.
Returns
A random number between low and high.

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)

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

Parameters
fileNameThe name of the file to read.
Returns
The content of the file as 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 ( )

Get a full line of user input.

Returns
The user's input as a string.

Get a full line of user input.

Returns
A string containing the user's input.

◆ getUserInputToken()

std::string getUserInputToken ( )

Get a single word or token of user input.

Returns
The user's input as a string.

Get a single word or token of user input.

Returns
A string containing the user's input.

◆ readInt()

int readInt ( )

Read an integer from user input.

Returns
The integer value entered by the user.

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 
)

Repeat a string a specified number of times.

Parameters
strThe string to repeat.
countThe number of times to repeat the string.
Returns
The resulting string after repetition.

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 
)

Set the terminal size on non-Windows systems.

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

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 
)

Split a string by a delimiter.

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

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)

Convert a string to an integer.

Parameters
strThe string to convert.
Returns
The integer value of the string.

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)

Convert a string to lowercase.

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

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)

Convert a string to uppercase.

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

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 
)

Print text with a typing effect.

Parameters
contentThe text content to print.
delayTimeThe delay time between characters in milliseconds.
colorThe color code for the text.

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 ( )

Wait 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.