summaryrefslogtreecommitdiffstats
path: root/src/gameboard.h
blob: e6b003cd2a36dab11e3497efd051119498830bfc (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
// Author: Denis Kozadaev - (c) 2025


#ifndef	__GAME_BOARD_H__
#define	__GAME_BOARD_H__

#include <stdlib.h>

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

typedef	TQValueList<int>	ValidMoves;

class GameBoard:public TQWidget
{
	TQ_OBJECT
public:

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

	void	newGame(int);
	void	setTips(bool);
	void	setKnight(bool);
	void	setRandomCell(bool);

private:
	int		config;
	int		map_size, curr;
	int		*map;
	int		kpos;	/* knight position (in the map) */
	TQPixmap	*xpm;
	TQPixmap	*kxpm;
	TQImage		*knight;
	ValidMoves	vmove;
	TQColor		paperColor;

	void	initMap(int);
	void	redrawMap();
	void	adjustDelta(int, int, int&, int&, int&, int&);
	void	predictMoves();
	void	ifAppend(ValidMoves&, int, int);
	void	fromLinear(int, int&, int&);
	void	generateCell();

	int	toMap(int, int);
	int	mayMove(int);
	int	toLinear(int, int);

protected:
	void	resizeEvent(TQResizeEvent *);
	void	mousePressEvent(TQMouseEvent *);
	void	paintEvent(TQPaintEvent *);
};

#endif	/* __GAME_BOARD_H__ */