source:
network-game/common/Game.cpp@
6319311
Last change on this file since 6319311 was 6319311, checked in by , 11 years ago | |
---|---|
|
|
File size: 1.2 KB |
Rev | Line | |
---|---|---|
[f419b09] | 1 | #include "Game.h" |
2 | ||
[0693e25] | 3 | #include <allegro5/allegro_primitives.h> |
4 | ||
[f419b09] | 5 | using namespace std; |
6 | ||
7 | Game::Game() { | |
8 | this->id = 0; | |
9 | this->name = ""; | |
[b92e6a7] | 10 | this->blueScore = 0; |
11 | this->redScore = 0; | |
12 | this->worldMap = NULL; | |
[f419b09] | 13 | } |
14 | ||
[233e736] | 15 | Game::Game(string name, string filepath) { |
[f419b09] | 16 | this->id = 0; |
17 | this->name = name; | |
[b92e6a7] | 18 | this->blueScore = 0; |
19 | this->redScore = 0; | |
[233e736] | 20 | this->worldMap = WorldMap::loadMapFromFile(filepath); |
[f419b09] | 21 | } |
22 | ||
23 | Game::~Game() { | |
[b92e6a7] | 24 | delete this->worldMap; |
[f419b09] | 25 | } |
26 | ||
[ab8fd40] | 27 | string Game::getName() { |
28 | return this->name; | |
29 | } | |
30 | ||
[b92e6a7] | 31 | int Game::getNumPlayers() { |
32 | return this->players.size(); | |
[f419b09] | 33 | } |
34 | ||
[b92e6a7] | 35 | map<unsigned int, Player*>& Game::getPlayers() { |
36 | return this->players; | |
37 | } | |
38 | ||
39 | int Game::getRedScore() { | |
40 | return this->redScore; | |
41 | } | |
42 | ||
43 | int Game::getBlueScore() { | |
44 | return this->blueScore; | |
45 | } | |
46 | ||
47 | WorldMap* Game::getMap() { | |
48 | return this->worldMap; | |
49 | } | |
50 | ||
51 | void Game::setId(unsigned int id) { | |
52 | this->id = id; | |
[2ee386d] | 53 | } |
54 | ||
[f419b09] | 55 | bool Game::addPlayer(Player* p) { |
[b48ef09] | 56 | if (players.find(p->id) == players.end()) { |
[f419b09] | 57 | players[p->id] = p; |
58 | return true; | |
59 | } | |
60 | else | |
61 | return false; | |
62 | } | |
63 | ||
[b92e6a7] | 64 | bool Game::removePlayer(unsigned int id) { |
[f419b09] | 65 | if (players.erase(id) == 1) |
66 | return true; | |
67 | else | |
68 | return false; | |
69 | } | |
[b92e6a7] | 70 | |
71 | void Game::setRedScore(int score) { | |
72 | this->redScore = score; | |
73 | } | |
74 | ||
75 | void Game::setBlueScore(int score) { | |
76 | this->blueScore = score; | |
77 | } |
Note:
See TracBrowser
for help on using the repository browser.