b77b42e010a226d8dacfa5e7e9b7d40816a9b298.svn-base (1605B)
1 #ifndef CONTEXT_H 2 #define CONTEXT_H 3 4 #include "Utils.h" 5 #include "Console.h" 6 #include "Event.h" 7 #include "Mapper.h" 8 #include "MiscDraw.h" 9 10 class Context 11 { 12 public: 13 14 Context() {} 15 16 virtual bool Load(const char* filename) = 0; 17 18 virtual bool Update() = 0; 19 20 SDL_Renderer* mRen; 21 EventFeed mFeed; 22 23 protected: 24 }; 25 26 class ContextManager : public EventReceiver 27 { 28 public: 29 30 ContextManager() {} 31 32 ContextManager(char* GameDataPath) : mGameDataPath(GameDataPath) {} 33 34 bool LogContext(Context* con, char* name); 35 36 bool LoadContext(char* ContextName); 37 38 bool ContextUpdate(); 39 40 bool EventProcess(Event eve); 41 42 protected: 43 44 char* mGameDataPath; 45 Context* mActiveContext; 46 std::vector<Context*> mContexts; 47 std::vector<char*> mNames; 48 49 }; 50 51 52 class GameOver : public Context, public EventReceiver 53 { 54 public: 55 56 GameOver() {}; 57 58 GameOver(SDL_Renderer* ren, SDL_Texture* splash) 59 { 60 mRen = ren; 61 mSplash = splash; 62 } 63 64 bool Update(); 65 66 bool EventProcess(Event eve); 67 68 EventFeed mFeed; 69 70 protected: 71 72 SDL_Texture* mSplash; 73 74 }; 75 76 class MapTest : public Context 77 { 78 public: 79 80 MapTest(SDL_Renderer* ren) : mRen(ren) 81 { 82 mMapper = new Mapper(); 83 } 84 85 bool Load(const char* filename) 86 { 87 cJSON* root = LoadJSON(filename); 88 //PrintJSON(root); 89 cJSON* map_test = cJSON_GetObjectItem(root, "map_test"); 90 int h = cJSON_GetObjectItem(map_test, "h")->valueint; 91 int w = cJSON_GetObjectItem(map_test, "w")->valueint; 92 93 mMapper->GenerateMap(h, w); 94 return false; 95 } 96 97 bool Update() 98 { 99 mMapper->AddFeature(); 100 DrawMapTest(mRen, mMapper->GetMap()); 101 return false; 102 } 103 104 protected: 105 106 SDL_Renderer* mRen; 107 Mapper* mMapper; 108 }; 109 110 #endif