/[enigma]/enigma/src/enigma.hh
ViewVC logotype

Diff of /enigma/src/enigma.hh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dheck, Sun Jan 19 17:58:33 2003 UTC revision 1.4 by dheck, Thu Jan 23 22:41:00 2003 UTC
# Line 19  Line 19 
19  #define ENIGMA_HH  #define ENIGMA_HH
20    
21  /*  /*
22   * This file contains   * This file contains declarations for facilities used by several
23   *   * different parts of the program, like common types and constants,
24   * a) Declarations for facilities used by several different parts of   * and routines for resource management.
  *    the program, like common types and constants, resource management,  
  *  
  * b) Functions for changing the game state like FinishLevel and  
  *    RestartLevel,  
  *  
  * c) Declarations for various game options.  
25   */   */
26    
27  #include "fwd.hh"  #include "fwd.hh"
28  #include "px/pxfwd.hh"  #include "px/pxfwd.hh"
29  #include "px/math.hh"  #include "px/math.hh"
30    #include "px/tools.hh"
31    
32  #include <string>  #include <string>
33  #include <vector>  #include <vector>
34  #include <iosfwd>  #include <iosfwd>
35    
36    /*
37    ** Import symbols from other namespaces
38    */
39  namespace enigma  namespace enigma
40  {  {
   
41      using std::string;      using std::string;
42      using std::vector;      using std::vector;
43    }
44    
45    //======================================================================
46    // APPLICATION
47    //======================================================================
48    namespace enigma
49    {
50        class Application {
51        public:
52            static Application *get_instance();
53    
54            void init(int argc, char **argv) {
55                copy(argv+1, argv+argc, back_inserter(args));
56            }
57    
58            // Variables.
59    
60            vector<string>  args;       // List of command line arguments.
61        };
62    }
63    
64    //======================================================================
65    // USEFUL DATA TYPES
66    //======================================================================
67    namespace enigma
68    {
69      enum Direction {      enum Direction {
70          NODIR = -1,          NODIR = -1,
71          NORTH = 3,          NORTH = 3,
# Line 73  namespace enigma Line 94  namespace enigma
94          return db & to_bits(dir);          return db & to_bits(dir);
95      }      }
96    
97    /*
98    ** Value
99    */
100    
101      /*      class Value {
102      ** GridPos      public:
103      */          enum Type { NIL, DOUBLE, STRING };
104    
105            Value() : type(NIL) {}
106            Value(double d) : type(DOUBLE) { val.dval = d; }
107            Value(const char* str);
108            ~Value() { clear(); }
109    
110            Value(const Value& v);
111            Value& operator=(const Value& v);
112    
113            void assign(double d) { clear(); type=DOUBLE; val.dval=d; }
114            void assign(const char* s);
115        
116            Type    get_type() const { return type; }
117            double  get_double() const throw();
118            const char* get_string() const throw();
119        private:
120            void clear();
121    
122            Type type;
123            union {
124                double dval;
125                char* str;
126            } val;
127        };
128    
129        px::Buffer& operator<<(px::Buffer& buf, const Value& val);
130        px::Buffer& operator>>(px::Buffer& buf, Value& val);
131        
132        std::ostream& operator<<(std::ostream& os, const Value& val);
133    
134        bool        to_bool(const Value &v);
135        int         to_int(const Value &v);
136        double      to_double(const Value &v);
137        const char *to_string(const Value &v);
138    
139    /*
140    ** TimeHandler / Timer
141    */
142        class TimeHandler {
143        public:
144            virtual ~TimeHandler() {}
145            virtual void tick(double dtime) {}
146            virtual void alarm() {}
147        };
148    
149        class Timer : public px::Nocopy {
150        public:
151            Timer();
152            ~Timer();
153            void activate(TimeHandler *th);
154            void deactivate(TimeHandler* th);
155            void set_alarm(TimeHandler* th, double interval, bool repeatp = false);
156            void remove_alarm(TimeHandler *cb);
157            void clear();
158    
159            void tick(double dtime);
160        private:
161            class Rep;
162            Rep &rep;
163        };
164    
165    
166    /*
167    ** GridPos
168    */
169      struct GridPos {      struct GridPos {
170          int x, y;          int x, y;
171          explicit GridPos(int xx=0, int yy=0) : x(xx), y(yy) {}          explicit GridPos(int xx=0, int yy=0) : x(xx), y(yy) {}
172    
173          void move(Direction dir);          void move(Direction dir);
174          bool operator==(GridPos b) const {          bool operator==(GridPos b) const { return (x==b.x && y==b.y); }
             return (x==b.x && y==b.y);  
         }  
175          bool operator!=(GridPos b) const { return (x!=b.x || y!=b.y); }          bool operator!=(GridPos b) const { return (x!=b.x || y!=b.y); }
176      };      };
177    
# Line 159  namespace enigma Line 246  namespace enigma
246    
247      px::Surface *LoadImage(const char *name);      px::Surface *LoadImage(const char *name);
248      px::Surface *GetImage(const char *name);      px::Surface *GetImage(const char *name);
   
 //======================================================================  
 // GAME STATE  
 //======================================================================  
   
 /*  
 ** Enigma can run its own levels but also emulate various versions of  
 ** Oxyd.  All these games behave similarly, but there are also quite a  
 ** few differences in object behaviour, visual appearance, etc.  The  
 ** game type is set at program startup and cannot be changed during  
 ** the game.  
 */  
     enum GameType {  
         GAMET_ENIGMA,  
         GAMET_OXYD1,  
         GAMET_PEROXYD,  
         GAMET_OXYDEXTRA,  
         GAMET_OXYDMAGNUM  
     };  
   
 /*  
 ** This datastructure contains information about single levels  
 */  
     struct LevelInfo  
     {  
         LevelInfo(const string &fn, const string &n, const string &a, int par_time=99*60+59)  
             : filename(fn), name(n), author(a), best_time(par_time)  
         {}  
   
         // Variables.  
         string filename;        // Filename of the level _without_ extension  
         string name;            // Complete name of the level  
         string author;          // Author of the level  
         int best_time;          // Best time in seconds  
     };  
   
     class LevelPack {  
     public:  
         LevelPack(const string &initfile, const string &n)  
             : init_file(initfile),name(n)  
         {}  
   
         // Load init_file to initialize the level list.  
         void init();  
   
         // Variables.  
         string init_file;       // Text file containing the level list  
         string name;            // Name of the level pack ("enigma", "oxyd", ...)  
         vector<LevelInfo> levels;  
     };  
   
     void AddLevelPack (const char *init_file, const char *name);  
   
     extern vector<LevelPack *> LevelPacks;  
     extern unsigned            CurrentLevelPack;  
 }  
   
 //----------------------------------------  
 // Interface to game engine  
 //----------------------------------------  
 namespace enigma  
 {  
     extern bool ConserveLevel;  // True: do not reset level when player dies  
     extern int Difficulty;      // Current difficulty level (0=easy,1=hard)  
   
     void StartGame (LevelPack *lp, unsigned levelidx);  
     void FinishLevel();  
     void RestartLevel();  
     void QuitGame();  
249  }  }
250    
251  #endif  #endif

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26