-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.cpp
92 lines (78 loc) · 1.27 KB
/
Game.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
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
#include "Game.h"
#include "Spawner.h"
using namespace std;
Game& Game::getInstance()
{
static Game instance;
return instance;
}
Game::~Game()
{
delete _map;
}
Game::Game()
{
_map = new Map;
try
{
_map->init("map.txt");
}
catch (exception &e)
{
cout << e.what() << endl;
return;
}
setGameState(GameState::playing);
}
void Game::start()
{
while (!isExiting())
{
gameLoop();
}
}
void Game::gameLoop()
{
draw();
nextMove();
}
void Game::nextMove()
{
_map->clearHasActed();
_map->getHero()->act(_map);
_map->getPrincess()->act(_map);
for (int i = 0; i < HEIGHT; ++i)
{
for (int j = 0; j < WIDTH; ++j)
{
if (!_map->hasActed(Vec2i(j, i)))
_map->getActor(Vec2i(j, i))->act(_map);
}
}
vector<RemoteSpawner*> spawners = _map->getSpawners();
for (auto spawner : spawners)
spawner->act(_map);
}
void Game::draw()
{
_map->draw();
cout << "Your hp : " << _map->getHero()->hitPoints() << endl;
cout << "Princess hp : " << _map->getPrincess()->hitPoints() << endl;
printLog();
}
void Game::printLog()
{
while (!_logMessages.empty())
{
cout << _logMessages.front();
_logMessages.pop();
}
}
void Game::setGameState(GameState state)
{
_gameState = state;
}
bool Game::isExiting()
{
return (_gameState == GameState::exiting ? true : false);
}