refactor: renamed snake to element and moved fruit to element. Removed a lot of unused functions and variables

This commit is contained in:
DarthMooMancer
2025-08-30 01:09:50 -04:00
parent d488f6464a
commit 96e5eb9930
15 changed files with 159 additions and 246 deletions
+15 -17
View File
@@ -1,7 +1,6 @@
#include <thread>
#include "point.hpp"
#include "fruit.hpp"
#include "snake.hpp"
#include <iostream>
#include "element.hpp"
#include "window.hpp"
#include "globals.hpp"
#include "input.hpp"
@@ -13,28 +12,27 @@ int main () {
Body body;
Head head;
bool running = true;
bool collision = false;
std::thread input_thread(
&Input::get_input, &input,
std::ref(head.m_head.m_direction),
std::ref(collision),
std::ref(running));
while (running) {
body.collision(head, collision);
window.update_score(fruit, body);
window.check_exit(running, body, collision);
head.get_new_point(head.m_head.m_direction);
body.collision(head);
body.add_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.m_collision) {
std::cout << "You died! Score: " + std::to_string(body.m_body.size()) << std::endl;
running = false;
}
head.get_new_pos();
body.get_new_points(head);
head.get_previous_point();
head.m_previous_head.set_new_point(head.m_head.m_row, head.m_head.m_col, head.m_head.m_direction);
fruit.reset(window.m_board, head.m_head.m_row, head.m_head.m_col, window.m_score);
window.m_board[head.m_head.m_row][head.m_head.m_col] = '*';
window.m_board[fruit.m_point.m_row][fruit.m_point.m_col] = 'X';
body.draw(window.m_board);
window.update_display(FPS);
body.clear(window.m_board);
head.m_head.clear(window.m_board);
fruit.get_new_pos(window.m_board, head, body.m_score);
window.update_display(fruit, head, body);
}
input_thread.join();