source: network-game/common/Game.cpp@ 2ee386d

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
3using namespace std;
4
5Game::Game() {
6 this->id = 0;
7 this->name = "";
8}
9
10Game::Game(string name) {
11 this->id = 0;
12 this->name = name;
13}
14
15Game::~Game() {
16}
17
18void Game::setId(int id) {
19 this->id = id;
20}
21
22int Game::getNumPlayers() {
23 return players.size();
24}
25
26void 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
34bool 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
43bool 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.