diff --git a/CMakeLists.txt b/CMakeLists.txt index ee4f305..903cbf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,13 @@ include_directories(include) set(SOURCES src/main.cpp + src/input.cpp ) add_executable(2048 ${SOURCES}) -# find_package(Curses REQUIRED) -# include_directories(${CURSES_INCLUDE_DIR}) -# target_link_libraries(2048 ${CURSES_LIBRARIES}) +find_package(Curses REQUIRED) +include_directories(${CURSES_INCLUDE_DIR}) +target_link_libraries(2048 ${CURSES_LIBRARIES}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/compile_commands.json b/compile_commands.json deleted file mode 120000 index c52ad08..0000000 --- a/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -compile_commands.json \ No newline at end of file diff --git a/include/globals.hpp b/include/globals.hpp new file mode 100644 index 0000000..c203563 --- /dev/null +++ b/include/globals.hpp @@ -0,0 +1,7 @@ +#ifndef GLOBALS_HPP +#define GLOBALS_HPP + +constexpr int ROW = 10; +constexpr int COL = 10; + +#endif diff --git a/include/input.hpp b/include/input.hpp new file mode 100644 index 0000000..7a43ce7 --- /dev/null +++ b/include/input.hpp @@ -0,0 +1,9 @@ +#ifndef INPUT_HPP +#define INPUT_HPP + +struct Input { + int _getch; + void get_input(bool &running); +}; + +#endif diff --git a/include/window.hpp b/include/window.hpp new file mode 100644 index 0000000..2f21189 --- /dev/null +++ b/include/window.hpp @@ -0,0 +1,6 @@ +#ifndef WINDOW_HPP +#define WINDOW_HPP + +// Add code here + +#endif diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..1944140 --- /dev/null +++ b/src/input.cpp @@ -0,0 +1,15 @@ +#include "input.hpp" +#include + +void Input::get_input(bool &running) { + while (running) { + initscr(); + cbreak(); + noecho(); + + _getch = getch(); + endwin(); + + if(_getch == 113) running = false; + } +} diff --git a/src/main.cpp b/src/main.cpp index 1055224..7aaff22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,14 @@ #include +#include +#include "input.hpp" int main() { - std::cout << "Hello World" << std::endl; + Input input; + bool running = true; + std::thread input_thread(&Input::get_input, &input, std::ref(running)); + while (running) { + std::cout << "Hello World" << std::endl; + } + input_thread.join(); return 0; } diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..e69de29