Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SAPER_H
- #define SAPER_H
- #include <SDL/SDL.h>
- #undef main
- #include <SDL/SDL_image.h>
- namespace Size
- {
- const int Field = 16;
- const int BoardX = 9;
- const int BoardY = 9;
- const int Mines = 10;
- const int hMargin = 8;
- const int vMargin = 8;
- const int Face = 32;
- const int FaceSpace = 8;
- const int BgR = 0xC0;
- const int BgG = 0xC0;
- const int BgB = 0xC0;
- }
- enum IMAGES
- {
- I_PLAY,
- I_WIN,
- I_LOSE,
- I_CLEAR,
- I_FLAG,
- I_CHECK,
- I_MINE,
- I_GOTMINE,
- COUNT
- };
- class CField
- {
- public:
- enum STATE { MINE = 1, FLAG = 2, CHECK = 4 };
- CField(): mAround(0), fAround(0), state(0) {};
- inline bool Is (STATE chstate) const { return state & chstate; };
- inline void Set (STATE flag, bool val) { if (val) state |= flag; else state &= ~flag; };
- int mAround;
- int fAround;
- private:
- int state;
- };
- class CApp
- {
- public:
- int Run();
- ~CApp() { IMG_Quit(); SDL_Quit(); };
- inline int Error() const { int r = error; error = 0; return r; };
- static int error;
- class CRes
- {
- public:
- CRes();
- inline SDL_Surface* operator[] (IMAGES img) { return surf[img]; };
- private:
- SDL_Surface** surf;
- };
- CRes res;
- class CBoard
- {
- public:
- int x;
- int y;
- CBoard():
- x(0), y(0), fields(0), created(false) {};
- bool Create();
- void Destroy();
- inline CField* operator() (int x_, int y_) const
- {
- if (x_ < 0 || x_ >= x || y_ < 0 || y_ >= y)
- return 0;
- return &fields[x_][y_];
- };
- inline operator bool() const { return created; };
- private:
- CField** fields;
- bool created;
- };
- CBoard board;
- class CTimer
- {
- public:
- CTimer():
- startTick(0), endTick(0), curTime(0), running(false) {};
- inline void Start()
- { startTick += SDL_GetTicks() - endTick; endTick = 0; running = true; };
- inline void Stop()
- { endTick = SDL_GetTicks(); running = false; };
- inline void Reset()
- { startTick = SDL_GetTicks(); endTick = 0; curTime = 0; };
- inline int operator()()
- { return running ? curTime = (SDL_GetTicks() - startTick) / 1000 + 1 : curTime; };
- private:
- unsigned int startTick;
- unsigned int endTick;
- int curTime;
- bool running;
- };
- CTimer timer;
- bool SetMine (int, int);
- bool Reset();
- bool Click (int, int);
- bool BothClick (int, int);
- bool game;
- bool dead;
- void Draw();
- bool Init();
- SDL_Surface* screen;
- int AbsX;
- int AbsY;
- int Mines;
- };
- int CApp::error = 0;
- #endif // SAPER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement