1 /***********************************************************************
2  *
3  * Copyright (C) 2007-2009, 2019 Graeme Gott <graeme@gottcode.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  ***********************************************************************/
19 
20 #ifndef BOARD_H
21 #define BOARD_H
22 
23 #include <QElapsedTimer>
24 #include <QWidget>
25 class QLabel;
26 class QMainWindow;
27 class QTimeLine;
28 class QTimer;
29 class Maze;
30 class Solver;
31 class Theme;
32 
33 class Board : public QWidget
34 {
35 	Q_OBJECT
36 public:
37 	Board(QMainWindow* parent);
38 	~Board();
39 
40 signals:
41 	void hintAvailable(bool available);
42 	void pauseChecked(bool checked);
43 	void pauseAvailable(bool run);
44 	void zoomInAvailable(bool available);
45 	void zoomOutAvailable(bool available);
46 	void finished(int seconds, int steps, int algorithm, int size);
47 
48 public slots:
49 	void newGame();
50 	void loadGame();
51 	void saveGame();
52 	void pauseGame(bool paused);
53 	void hint();
54 	void zoomIn();
55 	void zoomOut();
56 	void loadSettings();
57 
58 protected:
59 	virtual void keyPressEvent(QKeyEvent* event);
60 	virtual void paintEvent(QPaintEvent*);
61 	virtual void resizeEvent(QResizeEvent*);
62 
63 private slots:
64 	void updateStatusMessage();
65 
66 private:
67 	void scale();
68 	void generate(unsigned int seed);
69 	void finish();
70 	void renderBackground();
71 	void renderMaze();
72 	void renderDone();
73 	void renderPause();
74 	void renderText(QPainter* painter, const QString& message) const;
75 
76 	bool m_done;
77 	bool m_paused;
78 
79 	int m_total_targets;
80 	Maze* m_maze;
81 	QPoint m_start;
82 	QList<QPoint> m_targets;
83 	Solver* m_solver;
84 	QLabel* m_status_time_message;
85 	QLabel* m_status_steps_message;
86 	QLabel* m_status_remain_message;
87 	QTimer* m_status_timer;
88 
89 	bool m_show_path;
90 	bool m_smooth_movement;
91 	int m_col_delta;
92 	int m_row_delta;
93 	QTimeLine* m_move_animation;
94 
95 	Theme* m_theme;
96 	QPixmap m_back;
97 	int m_unit;
98 	int m_zoom;
99 	int m_max_zoom;
100 	int m_zoom_size;
101 
102 	// Player
103 	QPoint m_player;
104 	int m_player_angle;
105 	int m_player_steps;
106 	QElapsedTimer m_player_time;
107 	int m_player_total_time;
108 	unsigned int m_controls_up;
109 	unsigned int m_controls_down;
110 	unsigned int m_controls_left;
111 	unsigned int m_controls_right;
112 	unsigned int m_controls_flag;
113 	unsigned int m_controls_hint;
114 	QPoint m_hint;
115 	int m_hint_angle;
116 };
117 
118 #endif // BOARD_H
119