43 lines
712 B
C++
43 lines
712 B
C++
#ifndef ELEMENT_HPP
|
|
#define ELEMENT_HPP
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
#include "globals.hpp"
|
|
|
|
class Window;
|
|
|
|
enum Direction {
|
|
UP, DOWN, LEFT, RIGHT
|
|
};
|
|
|
|
struct Vector2i {
|
|
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);
|
|
};
|
|
|
|
class SnakeGame {
|
|
public:
|
|
SnakeGame();
|
|
~SnakeGame();
|
|
void run();
|
|
|
|
private:
|
|
Window* win;
|
|
std::vector<Vector2i> 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]);
|
|
bool segment_overlap();
|
|
bool exit_summary();
|
|
};
|
|
|
|
#endif // ELEMENT_HPP
|