Changeset b92e6a7 in network-game for common


Ignore:
Timestamp:
Sep 26, 2013, 8:29:14 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
f41a7f9
Parents:
321fbbc
Message:

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)

Location:
common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    r321fbbc rb92e6a7  
    66   this->id = 0;
    77   this->name = "";
     8   this->blueScore = 0;
     9   this->redScore = 0;
     10   this->worldMap = NULL;
    811}
    912
     
    1114   this->id = 0;
    1215   this->name = name;
     16   this->blueScore = 0;
     17   this->redScore = 0;
     18   this->worldMap = WorldMap::loadMapFromFile("../data/map.txt");
    1319}
    1420
    1521Game::~Game() {
    16 }
    17 
    18 void Game::setId(int id) {
    19    this->id = id;
     22   delete this->worldMap;
    2023}
    2124
    2225int Game::getNumPlayers() {
    23    return players.size();
     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;
    2447}
    2548
     
    3356}
    3457
    35 bool Game::removePlayer(int id) {
     58bool Game::removePlayer(unsigned int id) {
    3659   if (players.erase(id) == 1)
    3760      return true;
     
    3962      return false;
    4063}
     64
     65void Game::setRedScore(int score) {
     66   this->redScore = score;
     67}
     68
     69void Game::setBlueScore(int score) {
     70   this->blueScore = score;
     71}
  • common/Game.h

    r321fbbc rb92e6a7  
    1515
    1616#include "Player.h"
     17#include "WorldMap.h"
    1718
    1819using namespace std;
     
    2021class Game {
    2122private:
    22    int id;
     23   unsigned int id;
    2324   string name;
    24    map<int, Player*> players;
     25   map<unsigned int, Player*> players;
     26   WorldMap* worldMap;
     27   int blueScore;
     28   int redScore;
    2529
    2630public:
     
    3135
    3236   int getNumPlayers();
     37   map<unsigned int, Player*>& getPlayers();
     38   int getBlueScore();
     39   int getRedScore();
     40   WorldMap* getMap();
    3341
    34    void setId(int id);
     42   void setId(unsigned int id);
    3543   bool addPlayer(Player* p);
    36    bool removePlayer(int id);
     44   bool removePlayer(unsigned int id);
     45   void setBlueScore(int score);
     46   void setRedScore(int score);
    3747};
    3848
  • common/WorldMap.cpp

    r321fbbc rb92e6a7  
    194194WorldMap* WorldMap::loadMapFromFile(string filename)
    195195{
    196     WorldMap* m = NULL;
     196   WorldMap* m = NULL;
    197197
    198198   ifstream file(filename.c_str());
Note: See TracChangeset for help on using the changeset viewer.