00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GAME_MAP_H_
00022 #define GAME_MAP_H_
00023
00024 #include "../Config.h"
00025
00026 #include <vector>
00027 #include <string>
00028
00029 #include "SDL.h"
00030
00031 #include "GameDebug.h"
00032 #include "Bomb.h"
00033 #include "Flame.h"
00034 #include "MapLocation.h"
00035 #include "Moveable.h"
00036 #include "Player.h"
00037 #include "Powerup.h"
00038 #include "Tile.h"
00039
00040 #include "../Parse/ListParser.h"
00041 #include "../Parse/Parse.h"
00042 #include "../Util/Matrix.h"
00043 #include "../Util/GeneralException.h"
00044 #include "../Util/STL_Helper.h"
00045
00046 using std::vector; using std::string;
00051 namespace Game {
00052
00053 namespace Constants {
00054 const size_t MAP_NUM_ROWS=16;
00055 const size_t MAP_NUM_COLS=16;
00056
00077 const bool ALLOW_BOMB_STACKING=false;
00078 };
00082 class GameMap {
00083 public:
00084 GameMap();
00085 ~GameMap();
00086
00090 bool runGame(SDL_Surface* screen);
00091 void readMap(std::istream& input);
00092
00099 bool tileIsPassable(int x, int y) const;
00100
00102 void explodeTile(int x, int y);
00103
00108 void addPlayer(const std::string& blpFile, const std::string& cfgFile);
00109
00110 private:
00111
00112 enum FlameStatus {
00113 FLAME_STOP,
00114 FLAME_KEEP_GOING
00115 };
00116
00117 struct BombPlayerPair {
00118 BombPlayerPair(AbstractPlayer* owner);
00119 ~BombPlayerPair();
00120 AbstractPlayer* owner;
00121 Bomb* bomb;
00122 MapLocation bombLoc;
00123 bool markedForDeletion;
00124 bool operator < (const BombPlayerPair& other) const;
00125 bool operator == (const BombPlayerPair& other) const;
00126 };
00127
00128 class BombPairAtPred {
00129 GameMap* gameMap;
00130 int x, y;
00131 public:
00132 BombPairAtPred(GameMap* map, int mapX, int mapY);
00133 bool operator()(const BombPlayerPair* b);
00134 };
00135
00136 friend class BombPairAtPred;
00137
00138 struct MapTile {
00139 MapTile();
00140 ~MapTile();
00141 BombPlayerPair* bombOwnerPair;
00142 Powerup* powerup;
00143 AbstractTile* tile;
00144 Flame flame;
00145 };
00146
00147 void putBomb(AbstractPlayer* player);
00148 void blowUpBomb(BombPlayerPair* b);
00149
00150 void occupyTile(int x, int y);
00151 void deOccupyTile(int x, int y);
00152 bool isValidLocation(int x, int y) const;
00153 void removePowerupAt(int x, int y);
00154
00155 bool playerHitByBomb(AbstractPlayer* p);
00156
00157 bool moveObject(MoveableItem& m, Direction d, int speed, bool allowDirChange=true, int st = Constants::SLACK_TOLERANCE);
00158 bool moveHoriz(MoveableItem& m, int amount, int questionableHorizTileLoc, int slack, int st = Constants::SLACK_TOLERANCE);
00159 bool moveVert(MoveableItem& m, int amount, int questionableVertTileLoc, int slack, int st = Constants::SLACK_TOLERANCE);
00160
00161 MapLocation getEmptyStartSpot();
00162
00163 void deleteMarkedBombs();
00164
00165 FlameStatus handleBombChain(int x, int y, FlameType dir);
00166
00167 Util::Matrix<MapTile*> tileMatrix;
00168 std::list<AbstractPlayer*> playerList;
00169 std::list<MapLocation*> openStartLocations;
00170 std::set<BombPlayerPair*> bombPlayerSet;
00171 std::list<MapLocation*> tilesToExplode;
00172 };
00173
00174 };
00175
00176 #endif // ifndef GAME_MAP_H
00177