From 169d39d9747f8765071c00b074567bd3e334968f Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Mon, 1 Sep 2025 19:24:57 -0400 Subject: [PATCH] feat: added window, input and elements --- CMakeLists.txt | 8 +++++--- include/elements.hpp | 6 ++++++ include/globals.hpp | 7 +++++++ include/input.hpp | 10 ++++++++++ include/window.hpp | 12 ++++++++++++ src/elements.cpp | 0 src/input.cpp | 17 +++++++++++++++++ src/main.cpp | 14 +++++++++++++- src/window.cpp | 19 +++++++++++++++++++ 9 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 include/elements.hpp create mode 100644 include/globals.hpp create mode 100644 include/input.hpp create mode 100644 include/window.hpp create mode 100644 src/elements.cpp create mode 100644 src/input.cpp create mode 100644 src/window.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ad3450c..e6992dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,14 @@ include_directories(include) set(SOURCES src/main.cpp + src/input.cpp + src/window.cpp ) add_executable(tic_tac_toe ${SOURCES}) -# find_package(Curses REQUIRED) -# include_directories(${CURSES_INCLUDE_DIR}) -# target_link_libraries(tic_tac_toe ${CURSES_LIBRARIES}) +find_package(Curses REQUIRED) +include_directories(${CURSES_INCLUDE_DIR}) +target_link_libraries(tic_tac_toe ${CURSES_LIBRARIES}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/include/elements.hpp b/include/elements.hpp new file mode 100644 index 0000000..bdface1 --- /dev/null +++ b/include/elements.hpp @@ -0,0 +1,6 @@ +#ifndef ELEMENTS_HPP +#define ELEMENTS_HPP + +// Add code here + +#endif 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..70892f4 --- /dev/null +++ b/include/input.hpp @@ -0,0 +1,10 @@ +#ifndef INPUT_HPP +#define INPUT_HPP +// #include "elements.hpp" + +struct Input { + char m_getch = ' '; + void get_input(bool &running); +}; + +#endif // INPUT_HPP diff --git a/include/window.hpp b/include/window.hpp new file mode 100644 index 0000000..c5a22c8 --- /dev/null +++ b/include/window.hpp @@ -0,0 +1,12 @@ +#ifndef WINDOW_HPP +#define WINDOW_HPP + +#include +#include "globals.hpp" +// #include "elements.hpp" + +struct Window { + std::array, ROW> m_board = {}; + void update_display(); +}; +#endif diff --git a/src/elements.cpp b/src/elements.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..63361b1 --- /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(); + + m_getch = getch(); + + endwin(); + if(m_getch == 'q') { + running = false; + } + } +} diff --git a/src/main.cpp b/src/main.cpp index 1055224..3ca3ed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,18 @@ #include +#include +#include "window.hpp" +#include "input.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; + } + + input_thread.join(); return 0; } diff --git a/src/window.cpp b/src/window.cpp new file mode 100644 index 0000000..e78a6b6 --- /dev/null +++ b/src/window.cpp @@ -0,0 +1,19 @@ +#include "window.hpp" +#include +#include +#include + +void Window::update_display() { + for(std::array &row : m_board) { row.fill('.'); } + // Modify board + + // Refresh and draw screen + std::cout << "\033[H" << std::flush; + for(std::array &row : m_board) { + for(char &col : row) { + std::cout << col << " "; + } + std::cout << "\r\n"; + } + std::this_thread::sleep_for(std::chrono::milliseconds(200)); // 1000 / fps; 200ms = 5fps +}