-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinputs.cpp
More file actions
45 lines (42 loc) · 765 Bytes
/
inputs.cpp
File metadata and controls
45 lines (42 loc) · 765 Bytes
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
#include <conio.h>
#include <iostream>
#include <tuple>
#include <curses.h>
#include "inputs.h"
using namespace std;
// input class functions
char Input::getLastKey() {
// returns the last key that was pressed
return lastKey;
}
char Input::getInput() {
// gets the ascii of the key pressed by the user, and returns the char of it
char pressed;
int key = _getch();
flushinp();
switch (key) {
case 119:
pressed = 'w';
return pressed;
case 97:
pressed = 'a';
return pressed;
case 115:
pressed = 's';
return pressed;
case 100:
pressed = 'd';
return pressed;
default:
return getLastKey();
}
}
bool Input::keyPress() {
// determines if a key has been pressed
if (_kbhit()) {
return true;
}
else {
return false;
}
}