File: puzzle.H

package info (click to toggle)
xjig 2.4-14.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 892 kB
  • sloc: cpp: 10,177; makefile: 1,142; perl: 23
file content (66 lines) | stat: -rw-r--r-- 1,234 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _puzzle_h
#define _puzzle_h

#ifndef _vec2_h
#	include "vec2.h"
#endif
#ifndef _object_h
	// to get Piece
#	include "objects.H"
#endif

//
// Class to create a grid, which should be the frame for the puzzle-pieces
//

class Grid {
	public:
		Grid(int w,int h);
		~Grid();

		void Init(int maxx, int maxy);
		void Reset( int x, int y );
		void Randomize(int percent);

		Vec2 &P(int x,int y)				{ return p[x+width*y]; }
		const Real &X(int x,int y)		{ return p[x+width*y].X(); }
		const Real &Y(int x,int y)		{ return p[x+width*y].Y(); }

		int	Width()						{ return width; }
		int	Height()						{ return height; }

	private:
		int	width, height;
		int	max_width, max_height;
		Vec2	*p;
};

class Puzzle {
	public:
		Puzzle();
		~Puzzle();

		Piece &P(int x,int y)			{ return *(p[x+width*y]); }

		void Init(int img_width, int img_height, int dx, int dy, const char *sfx );
		int CheckForJoin( Piece *pi, int depth=0 );
		void DropTile( int x, int y ) {
			DropTile(x+y*width);
		}
		void DropTile( int i ) {
			delete p[i];
			p[i]=0;
			tiles_left--;
		}
		void Redraw();
		void Rotation();
		int Finished()		{ return (tiles_left<=1); }

	private:
		int	width,height;
		int	tiles_left;
		Piece			**p;
		Grid			*g;
};

#endif