-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake.hpp
51 lines (37 loc) · 1023 Bytes
/
snake.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by asuka on 09.03.2023.
//
# ifndef SNAKE_SNAKE_HPP
# define SNAKE_SNAKE_HPP
# include <deque>
# include <glm/vec2.hpp>
namespace snake {
class Board;
class Apple;
class SnakeRenderer;
enum class SnakeMove : std::uint8_t {
up, down, right, left,
};
class Snake {
friend SnakeRenderer;
public:
Snake(Board& board, Apple& apple, glm::ivec2 head);
~Snake() = default;
Snake(const Snake&) = delete;
Snake& operator=(const Snake&) = delete;
Snake(Snake&&) noexcept = delete;
Snake& operator=(Snake&&) noexcept = delete;
void move(SnakeMove move);
void try_eat();
[[nodiscard]] bool validate() const;
private:
Board& board_;
Apple& apple_;
bool should_move_tail_ = true;
glm::ivec2 head_ = {0, 0};
std::deque<glm::ivec2> tail_{};
void move_head(SnakeMove move);
void move_tail();
};
} // snake
# endif // SNAKE_SNAKE_HPP