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
+26 -15
View File
@@ -11,28 +11,39 @@ int main () {
Input input;
Fruit fruit;
Body body;
Head head;
bool running = true;
Point* segments[ROW * COL] = {};
segments[0] = new Point { 5, 5, '*', 1 };
// segments[1] = new Point { 6, 5, '@', 0 };
std::thread input_thread(
&Input::get_input, &input,
std::ref(head.m_direction),
std::ref(segments[0]->m_direction),
std::ref(running));
while (running) {
body.check_new_tail();
if(body.m_body.size() >= (ROW * COL)) {
std::cout << "You win! Score: " + std::to_string(body.m_body.size()) << std::endl;
running = false;
} else if(body.check_collision(head)) {
std::cout << "You died! Score: " + std::to_string(body.m_body.size()) << std::endl;
running = false;
get_new_pos(window.m_board, segments);
// body.check_new_tail();
// if(body.m_body.size() >= (ROW * COL)) {
// std::cout << "You win! Score: " + std::to_string(body.m_body.size()) << std::endl;
// running = false;
// } else if(body.check_collision(head)) {
// std::cout << "You died! Score: " + std::to_string(body.m_body.size()) << std::endl;
// running = false;
// }
// head.get_new_pos();
// // fruit.get_new_pos(window.m_board, head);
// body.get_new_pos(head);
//
// head.m_previous_head.set_new_point(head.m_head);
window.draw_display();
window.update_display(segments);
}
for(int i = 0; i < ROW; i++) {
for(int j = 0; j < COL; j++) {
delete window.m_board[i][j];
}
head.get_new_pos();
fruit.get_new_pos(window.m_board, head);
body.get_new_pos(head);
head.m_previous_head.set_new_point(head.m_head);
window.update_display(fruit, head, body);
}
input_thread.join();