changed from raw pointer arrays to vectors

This commit is contained in:
DarthMooMancer
2025-11-04 20:11:57 -05:00
parent 1af33ba5a4
commit 183be3c24a
5 changed files with 80 additions and 71 deletions
+7 -23
View File
@@ -1,41 +1,25 @@
#include <thread>
#include <iostream>
#include "element.hpp"
#include "window.hpp"
#include "globals.hpp"
#include "input.hpp"
int main () {
std::srand(std::time(0));
SnakeGame engine;
Window win;
bool running = true;
Vector2i* buf[MAX_LEN] = {}; // 2 for head, 1 for fruit, rest for tail
buf[HEAD] = new Vector2i { COL / 2, ROW / 2, '*' };
buf[PREVIOUS_HEAD] = new Vector2i { buf[HEAD]->x, buf[HEAD]->y, '.' };
buf[FRUIT] = new Vector2i { (rand() % COL), (rand() % ROW), 'o' };
std::thread input_thread([&] { get_input(engine.m_dir, engine.running ); } );
std::thread input_thread([&] { get_input(buf[HEAD]->m_dir, running ); } );
while (running) {
on_fruit_eaten(win.board, buf);
determine_index_zero_pos(buf);
move_tail_indicies(buf);
if(buf[MAX_LEN - 1] != nullptr) {
std::cout << "You filled the whole board and won! Score: " << get_score() << std::endl;
running = false;
} if(segment_overlap(buf)) {
std::cout << "You collided with yourself and died! Score: " << get_score() << std::endl;
running = false;
}
while (engine.exit_summary()) {
engine.on_fruit_eaten(win.board);
engine.determine_index_zero_pos();
engine.move_tail_indicies();
win.clear_display();
win.update_display(buf);
win.update_display(engine.buf);
win.draw_display(200);
}
input_thread.join();
for(auto& p : buf) delete p;
return 0;
}