starting an upgrade to move everything to just use ptrs and simplify the code a little

This commit is contained in:
DarthMooMancer
2025-09-24 14:25:03 -04:00
parent 626d7261d4
commit 0d47de8a7a
5 changed files with 73 additions and 48 deletions
+11 -13
View File
@@ -3,24 +3,22 @@
#include <chrono>
#include <thread>
void Window::update_display(Fruit &fruit, Head &head, Body &body) {
for(int i = 0; i < ROW; i++) {
for(int j = 0; j < ROW; j++) {
m_board[i][j] = '.';
}
}
m_board[head.m_head.m_row][head.m_head.m_col] = '*';
m_board[fruit.m_point.m_row][fruit.m_point.m_col] = 'o';
for(int i = 0; i < body.m_body.size(); i++) {
m_board[body.m_body.at(i).m_tail_pos.m_row][body.m_body.at(i).m_tail_pos.m_col] = '@';
}
void Window::draw_display() {
std::cout << "\033[H" << std::flush; // Clear screen
for(int i = 0; i < ROW; i++) {
for(int j = 0; j < ROW; j++) {
std::cout << m_board[i][j] << " ";
if(m_board[i][j] == nullptr) { std::cout << ". "; }
if(m_board[i][j] != nullptr) { std::cout << m_board[i][j]->m_symbol << " "; }
}
std::cout << "\r\n";
}
std::this_thread::sleep_for(std::chrono::milliseconds((int) (200))); // 1000 / fps; 200ms = 5fps
}
void Window::update_display(Point* segments[]) {
for(int i = 0; i < ROW * COL; i++) {
if(segments[i] != nullptr) {
m_board[segments[i]->m_row][segments[i]->m_col] = segments[i];
}
}
}