-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snake.cpp
53 lines (36 loc) · 1.02 KB
/
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
#include "Snake.h"
#include "SnakeThread.h"
#include "Utils.h"
#include <conio.h>
using namespace std;
void Snake::run() {
SnakeThread st;
st.StartInternalThread();
while (m_play) {
int key = _getch();
/* getch () function returns two keycodes for arrow keys. Arrow put to getch '\033' and '[' and letter from A to D (up, down, right, left).
Check if the first value is escape and skip */
if (key == 224)
key = _getch();
switch (key) {
case UP_ARROW:
st.setYDirection(V_NEG);
st.setXDirection(V_NUL);
break;
case DWN_ARROW:
st.setYDirection(V_POS);
st.setXDirection(V_NUL);
break;
case LEFT_ARROW:
st.setXDirection(V_NEG);
st.setYDirection(V_NUL);
break;
case RIGHT_ARROW:
st.setXDirection(V_POS);
st.setYDirection(V_NUL);
break;
default:
break;
}
}
}