-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.cpp
36 lines (30 loc) · 925 Bytes
/
commands.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
#include "commands.h"
Commands::Commands()
{
this->game = CHESS;
sharedMemory = new QSharedMemory("VoiceChess", NULL);
if (!sharedMemory->create(11)) {
qDebug() << "unable to create shared mem";
qDebug() << QString::fromUtf8(sharedMemory->errorString().toStdString().c_str());
}
}
Commands::Commands(int game, QString up, QString left, QString right, QString down) {
this->game = game;
dict.insert(up, "Up");
dict.insert(left, "Left");
dict.insert(right, "Right");
dict.insert(down, "Down");
}
bool Commands::validate(QString command) {
if (game == TETRIS && dict.contains(command)) {
Action action(game, dict.value(command));
action.execute();
return true;
}
else if (game == CHESS && command.split(" ").size() == 5) {
Action action(game, command);
action.execute();
return true;
}
return false;
}