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
+22 -13
View File
@@ -1,3 +1,4 @@
// Used ptr to take a copy of the head, move head move tail at end of array to previous head position from copy and make the old tail a nullptr
#include "element.hpp"
#include <cstdlib>
#include <ctime>
@@ -29,20 +30,28 @@ void Fruit::get_new_pos(char (&board)[ROW][COL], Head &head) {
}
}
void Head::get_new_pos() {
if (m_direction == -1) {
if (m_head.m_col <= 0) m_head.m_col = COL - 1;
else m_head.m_col--;
} else if (m_direction == 1) {
if (m_head.m_col >= COL - 1) m_head.m_col = 0;
else m_head.m_col++;
} else if (m_direction == -2) {
if (m_head.m_row <= 0) m_head.m_row = ROW - 1;
else m_head.m_row--;
} else if (m_direction == 2) {
if (m_head.m_row >= ROW - 1) m_head.m_row = 0;
else m_head.m_row++;
void get_new_pos(Point* (*board)[COL], Point** segments) {
Point new_point;
new_point.m_row = segments[0]->m_row;
new_point.m_col = segments[0]->m_col;
if (segments[0]->m_direction == -1) {
if (new_point.m_col <= 0) new_point.m_col = COL - 1;
else new_point.m_col--;
} else if (segments[0]->m_direction == 1) {
if (new_point.m_col >= COL - 1) new_point.m_col = 0;
else new_point.m_col++;
} else if (segments[0]->m_direction == -2) {
if (new_point.m_row <= 0) new_point.m_row = ROW - 1;
else new_point.m_row--;
} else if (segments[0]->m_direction == 2) {
if (new_point.m_row >= ROW - 1) new_point.m_row = 0;
else new_point.m_row++;
}
board[segments[0]->m_row][segments[0]->m_col] = nullptr;
segments[0]->m_row = new_point.m_row;
segments[0]->m_col = new_point.m_col;
board[segments[0]->m_row][segments[0]->m_col] = segments[0];
}
bool Body::check_collision(Head &head) {