window is no longer a raw pointer and is a unique_ptr, id no longer exists

This commit is contained in:
DarthMooMancer
2025-11-05 02:18:28 -05:00
parent e437b7b35f
commit 1160f3d147
4 changed files with 43 additions and 51 deletions
+9 -8
View File
@@ -2,6 +2,7 @@
#define ELEMENT_HPP
#include <cstdint>
#include <memory>
#include <vector>
#include "globals.hpp"
@@ -11,12 +12,12 @@ enum Direction {
UP, DOWN, LEFT, RIGHT
};
struct Vector2i {
struct vec {
int x, y;
char id;
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);
vec() : x(0), y(0) {}
vec(int x, int y) : x(x), y(y) {}
void set(int _x, int _y) { x = _x; y = _y; }
auto operator <=> (const vec&) const = default;
};
class SnakeGame {
@@ -26,15 +27,15 @@ public:
void run();
private:
Window* win;
std::vector<Vector2i> buf;
std::unique_ptr<Window> win;
std::vector<vec> buf;
bool running = true;
enum Direction m_dir;
uint8_t m_score = 0;
void process_input();
void determine_index_zero_pos();
void move_tail_indicies();
void on_fruit_eaten(Vector2i (*board)[COL]);
void add_tail_and_respawn_fruit(std::array<std::array<char, COL>, ROW> board);
bool segment_overlap();
bool exit_summary();
};
+3 -3
View File
@@ -3,12 +3,12 @@
#include "globals.hpp"
#include "element.hpp"
#include <array>
struct Window {
Vector2i board[ROW][COL] = {};
void clear_display();
std::array<std::array<char, COL>, ROW> board;
void draw_display();
void update_display(std::vector<Vector2i> &buf);
void update_display(std::vector<vec> &buf);
};
#endif // WINDOW_HPP