Add base game

This commit is contained in:
2024-07-04 16:57:11 -04:00
parent 85e4a03a90
commit 716ae24600
16 changed files with 520 additions and 11 deletions

11
conio/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
add_library(
conio
conio.hpp
conio.cpp
)
target_include_directories(
conio
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

30
conio/conio.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "conio.hpp"
#include <termios.h>
#include <unistd.h>
#include <iostream>
/**
* Get a character from the console without needing to press enter
*/
char conio::getch()
{
char c;
struct termios oldattr, newattr;
// Get the terminal settings
tcgetattr(STDIN_FILENO, &oldattr);
newattr = oldattr;
// Disable canonical mode and echo
newattr.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newattr);
// Get the character, will not wait for enter because of the new settings
std::cin.get(c);
// Reset the terminal settings back to normal behaviour
tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
return c;
}

9
conio/conio.hpp Normal file
View File

@ -0,0 +1,9 @@
#ifndef CONIO_HPP
#define CONIO_HPP
namespace conio
{
char getch();
}
#endif // CONIO_HPP