-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.c
65 lines (63 loc) · 1.44 KB
/
library.c
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
#include "battle_ship.h"
#include <stdbool.h>
char get_key () {
char signal;
char key;
bool escape;
signal = getchar ();
if (0x1b == signal) {
escape = true;
if (0x5b == getchar ()) {
signal = getchar ();
}
} else {
escape = false;
}
if (escape) {
switch (signal) {
case 0x41:
key = 'U';
break;
case 0x42:
key = 'D';
break;
case 0x43:
key = 'R';
break;
case 0x44:
key = 'L';
break;
default:
key = 'x';
break;
}
} else {
switch (signal) {
case 0x77: case 0x57:
key = 'U';
break;
case 0x73: case 0x53:
key = 'D';
break;
case 0x64: case 0x44:
key = 'R';
break;
case 0x61: case 0x41:
key = 'L';
break;
case 0x72: case 0x52:
key = 'r';
break;
case 0x71: case 0x51:
key = 'q';
break;
case 0x69: case 0x49: case 0x68: case 0x48:
key = 'h';
break;
default:
key = 'x';
break;
}
}
return key;
}