-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameController.h
88 lines (70 loc) · 1.78 KB
/
GameController.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef GAMECONTROLLER_H_
#define GAMECONTROLLER_H_
#include "SpriteManager.h"
#include <string>
#include <map>
#include <iostream>
#include <sstream>
const int INVALID_KEY = 0;
class GraphObject;
class GameWorld;
class GameController
{
public:
void run(int argc, char* argv[], GameWorld* gw, std::string windowTitle);
bool getLastKey(int& value)
{
if (m_lastKeyHit != INVALID_KEY)
{
value = m_lastKeyHit;
m_lastKeyHit = INVALID_KEY;
return true;
}
return false;
}
void playSound(int soundID);
void setGameStatText(std::string text)
{
m_gameStatText = text;
}
void doSomething();
void reshape(int w, int h);
void keyboardEvent(unsigned char key, int x, int y);
void specialKeyboardEvent(int key, int x, int y);
void quitGame();
// Meyers singleton pattern
static GameController& getInstance()
{
static GameController instance;
return instance;
}
static void timerFuncCallback(int nothing);
void setMsPerTick(int ms_per_tick) { m_ms_per_tick = ms_per_tick; }
private:
enum GameControllerState : int;
GameWorld* m_gw;
GameControllerState m_gameState;
GameControllerState m_nextStateAfterPrompt;
GameControllerState m_nextStateAfterAnimate;
int m_lastKeyHit;
bool m_singleStep;
std::string m_gameStatText;
std::string m_mainMessage;
std::string m_secondMessage;
int m_curIntraFrameTick;
using SoundMapType = std::map<int, std::string>;
using DrawMapType = std::map<int, std::string>;
SoundMapType m_soundMap;
bool m_playerWon;
SpriteManager m_spriteManager;
void setGameState(GameControllerState s);
void initDrawersAndSounds();
void displayGamePlay();
static const int kDefaultMsPerTick = 10;
static int m_ms_per_tick;
};
inline GameController& Game()
{
return GameController::getInstance();
}
#endif // GAMECONTROLLER_H_