engine: input added
This commit is contained in:
+4
-3
@@ -6,12 +6,13 @@ include_directories(include)
|
|||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/input.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(2048 ${SOURCES})
|
add_executable(2048 ${SOURCES})
|
||||||
|
|
||||||
# find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
# include_directories(${CURSES_INCLUDE_DIR})
|
include_directories(${CURSES_INCLUDE_DIR})
|
||||||
# target_link_libraries(2048 ${CURSES_LIBRARIES})
|
target_link_libraries(2048 ${CURSES_LIBRARIES})
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
compile_commands.json
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef GLOBALS_HPP
|
||||||
|
#define GLOBALS_HPP
|
||||||
|
|
||||||
|
constexpr int ROW = 10;
|
||||||
|
constexpr int COL = 10;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef INPUT_HPP
|
||||||
|
#define INPUT_HPP
|
||||||
|
|
||||||
|
struct Input {
|
||||||
|
int _getch;
|
||||||
|
void get_input(bool &running);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef WINDOW_HPP
|
||||||
|
#define WINDOW_HPP
|
||||||
|
|
||||||
|
// Add code here
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include "input.hpp"
|
||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
void Input::get_input(bool &running) {
|
||||||
|
while (running) {
|
||||||
|
initscr();
|
||||||
|
cbreak();
|
||||||
|
noecho();
|
||||||
|
|
||||||
|
_getch = getch();
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
if(_getch == 113) running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include "input.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
Input input;
|
||||||
|
bool running = true;
|
||||||
|
std::thread input_thread(&Input::get_input, &input, std::ref(running));
|
||||||
|
while (running) {
|
||||||
std::cout << "Hello World" << std::endl;
|
std::cout << "Hello World" << std::endl;
|
||||||
|
}
|
||||||
|
input_thread.join();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user