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
+19 -10
View File
@@ -1,28 +1,37 @@
#ifndef ELEMENT_HPP
#define ELEMENT_HPP
#include <vector>
#include "globals.hpp"
enum Direction {
UP = -2,
DOWN = 2,
LEFT = -1,
RIGHT = 1
UP, DOWN, LEFT, RIGHT
};
struct Vector2i {
int x, y;
char id;
enum Direction m_dir;
Vector2i() : x(0), y(0), id('@') {}
Vector2i(int x, int y, char s) : x(x), y(y), id(s) {}
void set(int x, int y);
};
int get_score();
void determine_index_zero_pos(Vector2i** buf);
void move_tail_indicies(Vector2i** buf);
void on_fruit_eaten(Vector2i (*board)[COL], Vector2i** buf);
bool segment_overlap(Vector2i** buf);
class SnakeGame {
public:
SnakeGame();
// ~SnakeGame();
// Vector2i* buf[MAX_LEN] = {};
std::vector<Vector2i> buf;
bool running = true;
enum Direction m_dir;
void determine_index_zero_pos();
void move_tail_indicies();
void on_fruit_eaten(Vector2i (*board)[COL]);
bool segment_overlap();
bool exit_summary();
private:
int m_score = 0;
// int m_snake_size = 3;
};
#endif // ELEMENT_HPP
+1 -1
View File
@@ -8,7 +8,7 @@ struct Window {
Vector2i board[ROW][COL] = {};
void clear_display();
void draw_display(int milliseconds);
void update_display(Vector2i** buf);
void update_display(std::vector<Vector2i> &buf);
};
#endif // WINDOW_HPP