-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snake.cpp
56 lines (49 loc) · 964 Bytes
/
Snake.cpp
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
53
54
55
56
struct Node
{
int x;
int y;
};
enum Direction{LEFT,RIGHT,UP,DOWN};
class SnakeGame
{
int height,width;
deque<Node> snake;
vector<vector<bool> > board;
Direction autoDirection;
bool autoMove()
{
int n1,nj;
Node head=snake.front();
if(autoDirection==RIGHT)
{
ni=head.i;
nj=head.j+1;
}
else if(autoDirection==DONW)
{
ni=head.i+1;
nj=head.j;
}
else if(autoDirection==LEFT)
{
ni=head.i;
nj=head.j-1;
}
else
{
ni=head.i-1;
nj=head.j;
}
if(ni<0||ni>=height||nj<0||nj>=width||board[ni][nj]==false)
{
return false;
}
Node newHead(ni,nj);
board[ni][nj]=false;
snake.push_front(newHead);
snake.pop_back();
}
bool changeDirection(Direction d)
{
}
}