1 #ifndef _puzzle_h 2 #define _puzzle_h 3 4 #ifndef _vec2_h 5 # include "vec2.h" 6 #endif 7 #ifndef _object_h 8 // to get Piece 9 # include "objects.H" 10 #endif 11 12 // 13 // Class to create a grid, which should be the frame for the puzzle-pieces 14 // 15 16 class Grid { 17 public: 18 Grid(int w,int h); 19 ~Grid(); 20 21 void Init(int maxx, int maxy); 22 void Reset( int x, int y ); 23 void Randomize(int percent); 24 P(int x,int y)25 Vec2 &P(int x,int y) { return p[x+width*y]; } X(int x,int y)26 const Real &X(int x,int y) { return p[x+width*y].X(); } Y(int x,int y)27 const Real &Y(int x,int y) { return p[x+width*y].Y(); } 28 Width()29 int Width() { return width; } Height()30 int Height() { return height; } 31 32 private: 33 int width, height; 34 int max_width, max_height; 35 Vec2 *p; 36 }; 37 38 class Puzzle { 39 public: 40 Puzzle(); 41 ~Puzzle(); 42 P(int x,int y)43 Piece &P(int x,int y) { return *(p[x+width*y]); } 44 45 void Init(int img_width, int img_height, int dx, int dy, const char *sfx ); 46 int CheckForJoin( Piece *pi, int depth=0 ); DropTile(int x,int y)47 void DropTile( int x, int y ) { 48 DropTile(x+y*width); 49 } DropTile(int i)50 void DropTile( int i ) { 51 delete p[i]; 52 p[i]=0; 53 tiles_left--; 54 } 55 void Redraw(); 56 void Rotation(); Finished()57 int Finished() { return (tiles_left<=1); } 58 59 private: 60 int width,height; 61 int tiles_left; 62 Piece **p; 63 Grid *g; 64 }; 65 66 #endif 67