-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameWorld.cpp
42 lines (38 loc) · 1000 Bytes
/
GameWorld.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
#include "GameWorld.h"
#include "GameController.h"
#include <string>
using namespace std;
int GameWorld::getAction(int playerNum)
{
queue<int>& pendingActions = m_pendingActions[playerNum-1];
if (!pendingActions.empty())
{
int action = pendingActions.front();
pendingActions.pop();
return action;
}
int key;
while (m_controller->getKeyIfAny(key))
{
auto it = m_keyMap.find(key);
if (it == m_keyMap.end()) // meaningless key
continue;
const KeyInfo& keyInfo = it->second;
if (keyInfo.playerNum == playerNum)
return keyInfo.action;
m_pendingActions[keyInfo.playerNum-1].push(keyInfo.action);
}
return ACTION_NONE;
}
void GameWorld::playSound(int soundID)
{
m_controller->playSound(soundID);
}
void GameWorld::setGameStatText(string text)
{
m_controller->setGameStatText(text);
}
void GameWorld::setMsPerTick(int ms_per_tick)
{
m_controller->setMsPerTick(ms_per_tick);
}