-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWorld.h
122 lines (99 loc) · 2.46 KB
/
GameWorld.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef GAMEWORLD_H_
#define GAMEWORLD_H_
#include "GameConstants.h"
#include <map>
#include <string>
#include <queue>
#include <chrono>
class GameController;
class GameWorld
{
public:
GameWorld(std::string assetPath)
: m_stars(0), m_coins(0), m_boardNumber(1), m_controller(nullptr),
m_assetPath(assetPath)
{
m_keyMap = {
{ 'a', { 1, ACTION_LEFT } },
{ 'd', { 1, ACTION_RIGHT } },
{ 'w', { 1, ACTION_UP } },
{ 's', { 1, ACTION_DOWN } },
{ KEY_PRESS_TAB, { 1, ACTION_ROLL } },
{ '`', { 1, ACTION_FIRE } },
{ KEY_PRESS_LEFT, { 2, ACTION_LEFT } },
{ KEY_PRESS_RIGHT, { 2, ACTION_RIGHT } },
{ KEY_PRESS_UP, { 2, ACTION_UP } },
{ KEY_PRESS_DOWN, { 2, ACTION_DOWN } },
{ KEY_PRESS_ENTER, { 2, ACTION_ROLL } },
{ '\\', { 2, ACTION_FIRE } },
};
if (!m_assetPath.empty() && m_assetPath.back() != '/')
m_assetPath.push_back('/');
}
virtual ~GameWorld()
{
}
virtual int init() = 0;
virtual int move() = 0;
virtual void cleanUp() = 0;
void setGameStatText(std::string text);
int getAction(int playerNum);
void playSound(int soundID);
int getBoardNumber() const
{
return m_boardNumber;
}
void setFinalScore(int stars, int coins)
{
m_stars = stars;
m_coins = coins;
}
void startCountdownTimer(int numSeconds)
{
m_countdownTimerDeadline = std::chrono::system_clock::now() +
std::chrono::seconds(numSeconds);
}
int timeRemaining() const
{
auto dur = m_countdownTimerDeadline - std::chrono::system_clock::now();
return static_cast<int>(dur.count() / decltype(dur)::period::den);
}
std::string assetPath() const
{
return m_assetPath;
}
// The following should be used by only the framework, not the student
void setBoardNumber(int boardNumber)
{
m_boardNumber = boardNumber;
}
void setController(GameController* controller)
{
m_controller = controller;
}
int getWinnerStars() const
{
return m_stars;
}
int getWinnerCoins() const
{
return m_coins;
}
void setMsPerTick(int ms_per_tick);
private:
struct KeyInfo
{
int playerNum;
int action;
};
int m_lives;
int m_stars;
int m_coins;
int m_boardNumber;
GameController* m_controller;
std::queue<int> m_pendingActions[2]; // 0 for Peach, 1 for Yoshi
std::string m_assetPath;
std::map<int, KeyInfo> m_keyMap;
std::chrono::system_clock::time_point m_countdownTimerDeadline;
};
#endif // GAMEWORLD_H_