00001 #ifndef XCLONE_TERRAIN_H 00002 #define XCLONE_TERRAIN_H 00003 00004 #include "includes.h" 00005 00006 enum TerrainType { GRASS, WATER }; 00007 00008 #define IMPASSABLE_TERRAIN_MULTIPLIER 1000.0 00009 00010 class Terrain 00011 { 00012 public: 00013 Terrain(TerrainType type); 00014 ~Terrain(); 00015 00016 bool isPassable() const; 00017 TerrainType getType() const; 00018 double getMoveMultiplier() const; 00019 void draw(int x, int y) const; 00020 00021 private: 00022 class TerrainBaseType; 00023 00024 TerrainBaseType* _type; 00025 static map<TerrainType, TerrainBaseType*> _possibleTypes; 00026 static map<TerrainType, SDL_Surface*> _imageMap; 00027 static int _refCount; 00028 00029 // inner classes for dealing with TerrainTypes 00030 class TerrainBaseType 00031 { 00032 public: 00033 virtual ~TerrainBaseType() {} 00034 virtual bool isPassable() = 0; 00035 virtual TerrainType getType() = 0; 00036 virtual double getMoveMultiplier() = 0; 00037 }; 00038 00039 class TerrainGrass : public TerrainBaseType 00040 { 00041 public: 00042 virtual bool isPassable() { return true; } 00043 virtual TerrainType getType() { return GRASS; } 00044 virtual double getMoveMultiplier() { return 1; } 00045 }; 00046 00047 class TerrainWater : public TerrainBaseType 00048 { 00049 public: 00050 virtual bool isPassable() { return false; } 00051 virtual TerrainType getType() { return WATER; } 00052 virtual double getMoveMultiplier() { return IMPASSABLE_TERRAIN_MULTIPLIER; } 00053 }; 00054 }; 00055 00056 #endif