-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputProcess.cpp
More file actions
57 lines (53 loc) · 1.3 KB
/
InputProcess.cpp
File metadata and controls
57 lines (53 loc) · 1.3 KB
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
#include "include.h"
std::vector<DirectionsAllowed> isDirectionsAllowed =
{
// up, down, left, right
{true, false, true, false},
{true, false, true, true},
{true, false, false, true},
{true, true, true, false},
{true, true, true, true},
{true, true, false, true},
{false, true, true, false},
{false, true, true, true},
{false, true, false, true}};
int GetEmptyIndex(std::vector<Tile> tiles)
{
for (int i = 0; i < tiles.size(); i++)
{
if (tiles[i].isEmpty == true)
{
return i;
}
}
std::cout << "Error: No empty tile found" << std::endl;
return -1;
}
bool IsKeyLegit(std::vector<Tile> tiles, int key)
{
int index = GetEmptyIndex(tiles);
if (key == KEY_UP)
{
return isDirectionsAllowed[index].isUpAllowed ? true : false;
}
else if (key == KEY_DOWN)
{
return isDirectionsAllowed[index].isDownAllowed ? true : false;
}
else if (key == KEY_LEFT)
{
return isDirectionsAllowed[index].isLeftAllowed ? true : false;
}
else if (key == KEY_RIGHT)
{
return isDirectionsAllowed[index].isRightAllowed ? true : false;
}
else if (key == -1)
{
exit(0);
}
else
{
return false;
}
}