forked from Whales/Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keypress.cpp
68 lines (66 loc) · 865 Bytes
/
keypress.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
57
58
59
60
61
62
63
64
65
66
67
68
#include "keypress.h"
long input()
{
long ch = getch();
switch (ch) {
case '7': return 'y';
case KEY_UP:
case '8': return 'k';
case '9': return 'u';
case KEY_LEFT:
case '4': return 'h';
case '5': return '.';
case KEY_RIGHT:
case '6': return 'l';
case '1': return 'b';
case KEY_DOWN:
case '2': return 'j';
case '3': return 'n';
case 459: return '\n';
default: return ch;
}
}
void get_direction(int &x, int &y, char ch)
{
x = 0;
y = 0;
switch (ch) {
case 'y':
x = -1;
y = -1;
return;
case 'u':
x = 1;
y = -1;
return;
case 'h':
x = -1;
return;
case 'j':
y = 1;
return;
case 'k':
y = -1;
return;
case 'l':
x = 1;
return;
case 'b':
x = -1;
y = 1;
return;
case 'n':
x = 1;
y = 1;
return;
case '.':
case ',':
case 'g':
x = 0;
y = 0;
return;
default:
x = -2;
y = -2;
}
}