diff --git a/CMakeLists.txt b/CMakeLists.txt index d35c1d8..5bfc35b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,13 @@ include_directories(include) set(SOURCES src/main.cpp + src/input.cpp ) add_executable(connect_four ${SOURCES}) -# find_package(Curses REQUIRED) -# include_directories(${CURSES_INCLUDE_DIR}) -# target_link_libraries(connect_four ${CURSES_LIBRARIES}) +find_package(Curses REQUIRED) +include_directories(${CURSES_INCLUDE_DIR}) +target_link_libraries(connect_four ${CURSES_LIBRARIES}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/include/input.hpp b/include/input.hpp new file mode 100644 index 0000000..1391276 --- /dev/null +++ b/include/input.hpp @@ -0,0 +1,9 @@ +#ifndef INPUT_HPP +#define INPUT_HPP + +struct Input { + int _getch = 0; + void get_input(bool &running); +}; + +#endif diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..b7ee291 --- /dev/null +++ b/src/input.cpp @@ -0,0 +1,17 @@ +#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..7441766 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,16 @@ #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; }