optimizations

This commit is contained in:
DarthMooMancer
2025-11-01 18:06:21 -04:00
parent f9d0e9fb01
commit 02ff154b81
8 changed files with 34 additions and 51 deletions
+6 -8
View File
@@ -8,23 +8,22 @@
int main () {
std::srand(std::time(0));
Window window;
Input input;
const int MAX_LEN = (ROW * COL) + 3;
bool running = true;
Point* buffer[MAX_LEN] = {}; // 2 for head, 1 for fruit, rest for tail
buffer[0] = new Point { ROW / 2, COL / 2, '*' }; // Head
buffer[1] = new Point { buffer[0]->m_row, buffer[0]->m_col, '.' };
buffer[2] = new Point { (rand() % ROW), (rand() % COL), 'o' }; // Fruit
std::thread input_thread([&] { input.get_input(buffer[0]->m_dir, running); } );
std::thread input_thread([&] { get_input(buffer[0]->m_dir, running ); } );
while (running) {
on_fruit_eaten(window.m_board, buffer);
determine_index_zero_pos(buffer);
move_tail_indicies(buffer);
for(int i = MAX_LEN - 1; i > 3; i--) {
if(buffer[i] == nullptr) break;
if(buffer[MAX_LEN - 1] != nullptr) {
std::cout << "You filled the whole board and won! Score: " << get_score() << std::endl;
running = false;
}
@@ -32,14 +31,13 @@ int main () {
std::cout << "You collided with yourself and died! Score: " << get_score() << std::endl;
running = false;
}
window.clear_display();
window.update_display(buffer);
window.draw_display(200);
}
input_thread.join();
for(int i = 0; i < MAX_LEN - 1; i++) {
delete buffer[i];
}
for(auto& p : buffer) delete p;
return 0;
}