Last change
on this file since 803566d was b92e6a7, checked in by dportnoy <dmp1488@…>, 11 years ago |
The Game class now has a WorldMap. When a client creates or joins a game, the server sends out all the basic game info (the map and info about all players in the game)
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[f419b09] | 1 | #include "Game.h"
|
---|
| 2 |
|
---|
| 3 | using namespace std;
|
---|
| 4 |
|
---|
| 5 | Game::Game() {
|
---|
| 6 | this->id = 0;
|
---|
| 7 | this->name = "";
|
---|
[b92e6a7] | 8 | this->blueScore = 0;
|
---|
| 9 | this->redScore = 0;
|
---|
| 10 | this->worldMap = NULL;
|
---|
[f419b09] | 11 | }
|
---|
| 12 |
|
---|
| 13 | Game::Game(string name) {
|
---|
| 14 | this->id = 0;
|
---|
| 15 | this->name = name;
|
---|
[b92e6a7] | 16 | this->blueScore = 0;
|
---|
| 17 | this->redScore = 0;
|
---|
| 18 | this->worldMap = WorldMap::loadMapFromFile("../data/map.txt");
|
---|
[f419b09] | 19 | }
|
---|
| 20 |
|
---|
| 21 | Game::~Game() {
|
---|
[b92e6a7] | 22 | delete this->worldMap;
|
---|
[f419b09] | 23 | }
|
---|
| 24 |
|
---|
[b92e6a7] | 25 | int Game::getNumPlayers() {
|
---|
| 26 | return this->players.size();
|
---|
[f419b09] | 27 | }
|
---|
| 28 |
|
---|
[b92e6a7] | 29 | map<unsigned int, Player*>& Game::getPlayers() {
|
---|
| 30 | return this->players;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | int Game::getRedScore() {
|
---|
| 34 | return this->redScore;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | int Game::getBlueScore() {
|
---|
| 38 | return this->blueScore;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | WorldMap* Game::getMap() {
|
---|
| 42 | return this->worldMap;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | void Game::setId(unsigned int id) {
|
---|
| 46 | this->id = id;
|
---|
[2ee386d] | 47 | }
|
---|
| 48 |
|
---|
[f419b09] | 49 | bool Game::addPlayer(Player* p) {
|
---|
| 50 | if (players.count(p->id) == 0) {
|
---|
| 51 | players[p->id] = p;
|
---|
| 52 | return true;
|
---|
| 53 | }
|
---|
| 54 | else
|
---|
| 55 | return false;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[b92e6a7] | 58 | bool Game::removePlayer(unsigned int id) {
|
---|
[f419b09] | 59 | if (players.erase(id) == 1)
|
---|
| 60 | return true;
|
---|
| 61 | else
|
---|
| 62 | return false;
|
---|
| 63 | }
|
---|
[b92e6a7] | 64 |
|
---|
| 65 | void Game::setRedScore(int score) {
|
---|
| 66 | this->redScore = score;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void Game::setBlueScore(int score) {
|
---|
| 70 | this->blueScore = score;
|
---|
| 71 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.