refactor: removing some deprecated functions and removed array for c style array

This commit is contained in:
DarthMooMancer
2025-09-12 20:31:42 -04:00
parent cfa0e52705
commit 4bab69a3a8
9 changed files with 33 additions and 58 deletions
+9 -16
View File
@@ -3,31 +3,24 @@
#include <chrono>
#include <thread>
Window::Window() {
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
}
void Window::update_display(Fruit &fruit, Head &head, Body &body) {
// Update symbols of positions
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] = 'X';
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] = '0';
m_board[body.m_body.at(i).m_tail_pos.m_row][body.m_body.at(i).m_tail_pos.m_col] = '@';
}
std::cout << "\033[H" << std::flush; // Clear screen
// Draw Screen
for(std::array<char, COL> &row : m_board) {
for(char &col : row) {
std::cout << col << " ";
for(int i = 0; i < ROW; i++) {
for(int j = 0; j < ROW; j++) {
std::cout << m_board[i][j] << " ";
}
std::cout << "\r\n";
}
std::this_thread::sleep_for(std::chrono::milliseconds((int) (200))); // 1000 / fps; 200ms = 5fps
// Clear old spaces
for(int i = 0; i < body.m_body.size(); i++) {
body.m_body.at(i).m_tail_pos.clear(m_board);
}
head.m_head.clear(m_board);
fruit.m_point.clear(m_board);
}