Advertisement
Guest User

Untitled

a guest
Oct 29th, 2010
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #ifndef SAPER_H
  2. #define SAPER_H
  3. #include <SDL/SDL.h>
  4. #undef main
  5. #include <SDL/SDL_image.h>
  6.  
  7. namespace Size
  8. {
  9.     const int Field = 16;
  10.     const int BoardX = 9;
  11.     const int BoardY = 9;
  12.     const int Mines = 10;
  13.     const int hMargin = 8;
  14.     const int vMargin = 8;
  15.     const int Face = 32;
  16.     const int FaceSpace = 8;
  17.     const int BgR = 0xC0;
  18.     const int BgG = 0xC0;
  19.     const int BgB = 0xC0;
  20. }
  21.  
  22. enum IMAGES
  23. {
  24.     I_PLAY,
  25.     I_WIN,
  26.     I_LOSE,
  27.     I_CLEAR,
  28.     I_FLAG,
  29.     I_CHECK,
  30.     I_MINE,
  31.     I_GOTMINE,
  32.     COUNT
  33. };
  34.  
  35. class CField
  36. {
  37.     public:
  38.     enum STATE { MINE = 1, FLAG = 2, CHECK = 4 };
  39.  
  40.     CField(): mAround(0), fAround(0), state(0) {};
  41.  
  42.     inline bool Is (STATE chstate) const { return state & chstate; };
  43.     inline void Set (STATE flag, bool val) { if (val) state |= flag; else state &= ~flag; };
  44.  
  45.     int mAround;
  46.     int fAround;
  47.     private:
  48.     int state;
  49. };
  50.  
  51. class CApp
  52. {
  53.     public:
  54.     int Run();
  55.     ~CApp() { IMG_Quit(); SDL_Quit(); };
  56.     inline int Error() const { int r = error; error = 0; return r; };
  57.     static int error;
  58.  
  59.     class CRes
  60.     {
  61.         public:
  62.         CRes();
  63.         inline SDL_Surface* operator[] (IMAGES img) { return surf[img]; };
  64.         private:
  65.         SDL_Surface** surf;
  66.     };
  67.     CRes res;
  68.  
  69.     class CBoard
  70.     {
  71.         public:
  72.         int x;
  73.         int y;
  74.         CBoard():
  75.         x(0), y(0), fields(0), created(false) {};
  76.         bool Create();
  77.         void Destroy();
  78.  
  79.         inline CField* operator() (int x_, int y_) const
  80.         {
  81.             if (x_ < 0 || x_ >= x || y_ < 0 || y_ >= y)
  82.                 return 0;
  83.             return &fields[x_][y_];
  84.         };
  85.         inline operator bool() const { return created; };
  86.  
  87.         private:
  88.         CField** fields;
  89.         bool created;
  90.     };
  91.     CBoard board;
  92.  
  93.     class CTimer
  94.     {
  95.         public:
  96.         CTimer():
  97.         startTick(0), endTick(0), curTime(0), running(false) {};
  98.         inline void Start()
  99.         { startTick += SDL_GetTicks() - endTick; endTick = 0; running = true; };
  100.         inline void Stop()
  101.         { endTick = SDL_GetTicks(); running = false; };
  102.         inline void Reset()
  103.         { startTick = SDL_GetTicks(); endTick = 0; curTime = 0; };
  104.         inline int operator()()
  105.         { return running ? curTime = (SDL_GetTicks() - startTick) / 1000 + 1 : curTime; };
  106.  
  107.         private:
  108.         unsigned int startTick;
  109.         unsigned int endTick;
  110.         int curTime;
  111.         bool running;
  112.     };
  113.     CTimer timer;
  114.  
  115.     bool SetMine (int, int);
  116.     bool Reset();
  117.     bool Click (int, int);
  118.     bool BothClick (int, int);
  119.     bool game;
  120.     bool dead;
  121.     void Draw();
  122.     bool Init();
  123.     SDL_Surface* screen;
  124.  
  125.     int AbsX;
  126.     int AbsY;
  127.     int Mines;
  128. };
  129. int CApp::error = 0;
  130. #endif // SAPER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement