-
Notifications
You must be signed in to change notification settings - Fork 19
/
input.cpp
55 lines (48 loc) · 936 Bytes
/
input.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
#include "input.h"
#include <termios.h>
#include <unistd.h>
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
using namespace std;
struct termios t;
void input_enter_off()
{
tcgetattr(STDIN_FILENO, &t);
t.c_lflag &= ~ICANON;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
}
void input_enter_on()
{
tcgetattr(STDIN_FILENO, &t);
t.c_lflag |= ICANON;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
}
enum Direction get_input()
{
enum Direction result = East;
char user_input = getchar();
switch (user_input)
{
case 'a':
result = West;
break;
case 'w':
result = North;
break;
case 'd':
result = East;
break;
case 's':
result = South;
break;
default:
result = Error;
cout << "Incorrect button clicked(" << user_input << ")" << endl;
break;
}
return result;
}
void input_init()
{
}