cleaning up
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
#ifndef ELEMENT_HPP
|
||||
#define ELEMENT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <globals.hpp>
|
||||
|
||||
class Window;
|
||||
constexpr int ROW = 11;
|
||||
constexpr int COL = 11;
|
||||
|
||||
enum class Direction {
|
||||
UP, DOWN, LEFT, RIGHT
|
||||
@@ -14,32 +12,35 @@ enum class Direction {
|
||||
|
||||
struct vec2 {
|
||||
int x, y;
|
||||
vec2() : x(0), y(0) {}
|
||||
vec2(int x, int y) : x(x), y(y) {}
|
||||
void set(int _x, int _y) { x = _x; y = _y; }
|
||||
auto operator <=> (const vec2&) const = default;
|
||||
};
|
||||
|
||||
class SnakeGame {
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> view;
|
||||
void draw_display();
|
||||
void update_display(vec2 &head, vec2 &fruit, std::vector<vec2> &buf);
|
||||
};
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
SnakeGame();
|
||||
~SnakeGame();
|
||||
Engine();
|
||||
~Engine();
|
||||
void run();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Window> win;
|
||||
Window win;
|
||||
std::vector<vec2> buf;
|
||||
vec2 head { COL / 2, ROW / 2 };
|
||||
vec2 fruit { rand() % COL, rand() % ROW };
|
||||
vec2 prev_head { head.x, head.y };
|
||||
struct {
|
||||
Direction dir = Direction::RIGHT;
|
||||
uint8_t m_score = 0;
|
||||
} state;
|
||||
Direction dir = Direction::RIGHT;
|
||||
unsigned int m_score = 0;
|
||||
bool process_input();
|
||||
void determine_index_zero_pos();
|
||||
void move_tail_indicies();
|
||||
void add_tail_and_respawn_fruit(std::array<std::array<char, COL>, ROW> view);
|
||||
void add_tail_and_respawn_fruit();
|
||||
bool exit_summary();
|
||||
};
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef GLOBALS_HPP
|
||||
#define GLOBALS_HPP
|
||||
constexpr int ROW = 11;
|
||||
constexpr int COL = 11;
|
||||
constexpr int MAX_LEN = (ROW * COL) + 3;
|
||||
constexpr int HEAD = 0;
|
||||
constexpr int PREVIOUS_HEAD = 1;
|
||||
constexpr int FRUIT = 2;
|
||||
#endif // GLOBALS_HPP
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef WINDOW_HPP
|
||||
#define WINDOW_HPP
|
||||
|
||||
#include <globals.hpp>
|
||||
#include <element.hpp>
|
||||
#include <array>
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> view;
|
||||
void draw_display();
|
||||
void update_display(vec2 &head, vec2 &fruit, std::vector<vec2> &buf);
|
||||
};
|
||||
|
||||
#endif // WINDOW_HPP
|
||||
Reference in New Issue
Block a user