Last change
on this file since 2ee386d was 2ee386d, checked in by dportnoy <dmp1488@…>, 11 years ago |
Clients store the total number of players in each game
|
-
Property mode
set to
100644
|
File size:
779 bytes
|
Line | |
---|
1 | #include "Game.h"
|
---|
2 |
|
---|
3 | using namespace std;
|
---|
4 |
|
---|
5 | Game::Game() {
|
---|
6 | this->id = 0;
|
---|
7 | this->name = "";
|
---|
8 | }
|
---|
9 |
|
---|
10 | Game::Game(string name) {
|
---|
11 | this->id = 0;
|
---|
12 | this->name = name;
|
---|
13 | }
|
---|
14 |
|
---|
15 | Game::~Game() {
|
---|
16 | }
|
---|
17 |
|
---|
18 | void Game::setId(int id) {
|
---|
19 | this->id = id;
|
---|
20 | }
|
---|
21 |
|
---|
22 | int Game::getNumPlayers() {
|
---|
23 | return players.size();
|
---|
24 | }
|
---|
25 |
|
---|
26 | void Game::setNumPlayers(int numPlayers) {
|
---|
27 | int numCurPlayers = this->getNumPlayers();
|
---|
28 | int numNewPlayers = numPlayers-numCurPlayers;
|
---|
29 |
|
---|
30 | for (int i=0; i<numNewPlayers; i++)
|
---|
31 | this->players[numCurPlayers+i] = NULL;
|
---|
32 | }
|
---|
33 |
|
---|
34 | bool Game::addPlayer(Player* p) {
|
---|
35 | if (players.count(p->id) == 0) {
|
---|
36 | players[p->id] = p;
|
---|
37 | return true;
|
---|
38 | }
|
---|
39 | else
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool Game::removePlayer(int id) {
|
---|
44 | if (players.erase(id) == 1)
|
---|
45 | return true;
|
---|
46 | else
|
---|
47 | return false;
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.