source: network-game/common/Game.cpp@ b48ef09

Last change on this file since b48ef09 was b48ef09, checked in by dportnoy <dmp1488@…>, 11 years ago

New message types and server code for creating and joining games

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "Game.h"
2
3using namespace std;
4
5Game::Game() {
6 this->id = 0;
7 this->name = "";
8 this->blueScore = 0;
9 this->redScore = 0;
10 this->worldMap = NULL;
11}
12
13Game::Game(string name) {
14 this->id = 0;
15 this->name = name;
16 this->blueScore = 0;
17 this->redScore = 0;
18 this->worldMap = WorldMap::loadMapFromFile("../data/map.txt");
19}
20
21Game::~Game() {
22 delete this->worldMap;
23}
24
25int Game::getNumPlayers() {
26 return this->players.size();
27}
28
29map<unsigned int, Player*>& Game::getPlayers() {
30 return this->players;
31}
32
33int Game::getRedScore() {
34 return this->redScore;
35}
36
37int Game::getBlueScore() {
38 return this->blueScore;
39}
40
41WorldMap* Game::getMap() {
42 return this->worldMap;
43}
44
45void Game::setId(unsigned int id) {
46 this->id = id;
47}
48
49bool Game::addPlayer(Player* p) {
50 if (players.find(p->id) == players.end()) {
51 players[p->id] = p;
52 return true;
53 }
54 else
55 return false;
56}
57
58bool Game::removePlayer(unsigned int id) {
59 if (players.erase(id) == 1)
60 return true;
61 else
62 return false;
63}
64
65void Game::setRedScore(int score) {
66 this->redScore = score;
67}
68
69void Game::setBlueScore(int score) {
70 this->blueScore = score;
71}
Note: See TracBrowser for help on using the repository browser.