feat: first time using setw but its interesting; used in window for numbers
This commit is contained in:
@@ -7,6 +7,7 @@ include_directories(include)
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
src/input.cpp
|
||||
src/window.cpp
|
||||
)
|
||||
|
||||
add_executable(2048 ${SOURCES})
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+7
-1
@@ -1,6 +1,12 @@
|
||||
#ifndef WINDOW_HPP
|
||||
#define WINDOW_HPP
|
||||
|
||||
// Add code here
|
||||
#include "globals.hpp"
|
||||
#include <array>
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<int, COL>, ROW> m_board = {};
|
||||
void draw_window();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+7
-1
@@ -1,14 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "window.hpp"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
void Window::draw_window() {
|
||||
// for(std::array<int, COL> &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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user