feat: window and input handling
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#include "input.hpp"
|
||||
#include <ncurses.h>
|
||||
|
||||
void Input::get_input(bool &running) {
|
||||
while(running) {
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
m_getch = getch();
|
||||
|
||||
endwin();
|
||||
if(m_getch == 'q') {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-1
@@ -1,6 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "input.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World" << std::endl;
|
||||
Input input;
|
||||
Window window;
|
||||
|
||||
bool running = true;
|
||||
std::thread input_thread(&Input::get_input, &input, std::ref(running));
|
||||
|
||||
while (running) {
|
||||
std::cout << "Hello World" << std::endl;
|
||||
window.update_display();
|
||||
|
||||
}
|
||||
input_thread.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "window.hpp"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
void Window::update_display() {
|
||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
||||
// Modify board
|
||||
|
||||
// Refresh and draw screen
|
||||
std::cout << "\033[H" << std::flush;
|
||||
for(std::array<char, COL> &row : m_board) {
|
||||
for(char &col : row) {
|
||||
std::cout << col << " ";
|
||||
}
|
||||
std::cout << "\r\n";
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(130)); // 1000 / fps; 200ms = 5fps
|
||||
}
|
||||
Reference in New Issue
Block a user