summaryrefslogtreecommitdiffstats
path: root/tdefifteen/src/gameboard.h
blob: 5b00131c1af1a48a3ddf6aee3440c20d5f52023e (plain)
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
67
68
// Author: Denis Kozadaev - (c) 2017-2020


#ifndef	__GAME_BOARD_H__
#define	__GAME_BOARD_H__

#include <stdlib.h>

#include <tqwidget.h>
#include <tqlabel.h>
#include <tqpixmap.h>
#include <tqtimer.h>


class BoardItem:public TQLabel
{
public:

	BoardItem(int, TQWidget *parent = NULL, const char *name = NULL);
	~BoardItem();

	int	item()const{return (num);}

private:
	int	num;

protected:
	void	paintEvent(TQPaintEvent *);
};

//------------------------------------------------------------------------------

class GameBoard:public TQWidget
{
	TQ_OBJECT
public:

	GameBoard(TQWidget *parent = NULL, const char *name = NULL);
	~GameBoard();

	void	newGame();
	void	loadImage();

private:
	int		n, nt, xt, yt, dx, dy;
	BoardItem	*map[16];
	TQTimer		*tmr;
	TQPixmap	origin;

	void	initMap();
	void	startMoving(int, int);
	void	checkEndGame();
	void	newTask();

	int	index(int, int);
	int	mayMove(int);
	int	step(int, int);
	int	sign(int);

protected:
	void	resizeEvent(TQResizeEvent *);
	void	mousePressEvent(TQMouseEvent *);

private slots:
	void	moveItem();
};

#endif	/* __GAME_BOARD_H__ */