diff --git a/CMakeLists.txt b/CMakeLists.txt index 903cbf7..e1a5654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories(include) set(SOURCES src/main.cpp src/input.cpp + src/window.cpp ) add_executable(2048 ${SOURCES}) diff --git a/include/globals.hpp b/include/globals.hpp index c203563..a37ccee 100644 --- a/include/globals.hpp +++ b/include/globals.hpp @@ -1,7 +1,7 @@ #ifndef GLOBALS_HPP #define GLOBALS_HPP -constexpr int ROW = 10; -constexpr int COL = 10; +constexpr int ROW = 4; +constexpr int COL = 4; #endif diff --git a/include/window.hpp b/include/window.hpp index 2f21189..88aefe1 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -1,6 +1,12 @@ #ifndef WINDOW_HPP #define WINDOW_HPP -// Add code here +#include "globals.hpp" +#include + +struct Window { + std::array, ROW> m_board = {}; + void draw_window(); +}; #endif diff --git a/src/main.cpp b/src/main.cpp index 7aaff22..2c0e3a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,20 @@ #include #include #include "input.hpp" +#include "window.hpp" int main() { Input input; + Window window; bool running = true; std::thread input_thread(&Input::get_input, &input, std::ref(running)); + + + window.m_board[0][0] = 4; while (running) { - std::cout << "Hello World" << std::endl; + window.draw_window(); } + input_thread.join(); return 0; } diff --git a/src/window.cpp b/src/window.cpp index e69de29..644980e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -0,0 +1,17 @@ +#include "window.hpp" +#include +#include +#include + +void Window::draw_window() { + // for(std::array &row : m_board) { row.fill(0); } + std::cout << "\033[H" << std::flush; + for(int i = 0; i < ROW; i++) { + for(int j = 0; j < COL; j++) { + if(m_board[i][j] == 0) std::cout << std::setw(4) << '.'; + else std::cout << std::setw(4) << m_board[i][j]; + } + std::cout << "\r\n"; + } + std::this_thread::sleep_for(std::chrono::milliseconds(200)); +}