-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.h
52 lines (37 loc) · 1.14 KB
/
snake.h
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
52
#ifndef SNAKE_H
#define SNAKE_H
#include <functional>
using GridIndex = int;
struct Node {
GridIndex mIndex{ 0 };
//FoodType mFood();// need to do some thing with this
Node* mNext{ nullptr };
Node* mPrev{ nullptr };
Node(GridIndex i) : mIndex(i) {}
Node(GridIndex i, Node* next, Node* prev) : mIndex(i), mNext(next), mPrev(prev) {}
};
class Snake {
public:
Snake() = default;
Snake(GridIndex head);
Snake(const Snake&) = delete;
Snake(Snake&&) = default;
~Snake();
void delete_snake();
inline unsigned size() const { return mLength; }
inline bool empty() const { return mHead == nullptr; }
inline GridIndex get_head() const { return mHead->mIndex; }
void push_back(GridIndex);
void pop_back();
void push_front(GridIndex);
void pop_front();
bool collision(GridIndex);
void foreach(std::function<void(int)>) const;
void test();
private:
Node* mHead{ nullptr };
Node* mTail{ nullptr };
unsigned mLength{ 0 };
// unsigned mPlayHead{ 0 };
};
#endif