1/*
2
3 Copyright (C) 1998 Andreas Wüst (AndreasWuest@gmx.de)
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 2 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, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 */
20#ifndef GAMEWIDGET_H
21#define GAMEWIDGET_H
22
23class PlayField;
24class QGraphicsView;
25class QTimer;
26
27#include <QWidget>
28#include "levelset.h"
29
30class KAtomicHighscores;
31
32class GameWidget : public QWidget
33{
34 Q_OBJECT
35
36public:
37 GameWidget ( const QString& levelSet, QWidget *parent );
38 ~GameWidget();
39
40 bool setLevelSet(const QString& levelSet);
41
42 /**
43 * @return levelset name
44 */
45 const LevelSet& levelSet() const;
46
47 void enableSwitchToAnyLevel() { m_allowAnyLevelSwitch = true; }
48 bool switchToAnyLevelAllowed() const { return m_allowAnyLevelSwitch; }
49
50 PlayField* playfield() { return m_playField; }
51
52 int currentLevel() const { return m_level; }
53 QString currentMolecule() const;
54 int currentScore() const { return m_moves; }
55 int currentHighScore() const;
56
57 bool isNextLevelAvailable() const;
58 bool isPrevLevelAvailable() const;
59
60 void saveMaxAccessibleLevel(int level);
61 void saveLastPlayedLevel();
62
63signals:
64 void statsChanged(int level,int score,int highscore);
65 void levelChanged(int level);
66
67public slots:
68 void prevLevel();
69 void nextLevel();
70
71 void saveGame();
72 void loadGame();
73
74 // restart current level
75 void restartLevel();
76
77 void gameOver(int moves);
78
79 // use this slot to update the moves continually
80 void updateMoves(int moves);
81
82 void showHighscores ();
83
84 void moveUp();
85 void moveDown();
86 void moveLeft();
87 void moveRight();
88private:
89
90 virtual void resizeEvent( QResizeEvent* );
91 void switchToLevel (int);
92
93 int lastPlayedLevel() const;
94 int maxAccessibleLevel() const;
95
96 /**
97 * If on, katomic will allow user to switch to any
98 * level even if she didn't solved it yet.
99 */
100 bool m_allowAnyLevelSwitch;
101
102 QGraphicsView *m_view;
103 PlayField *m_playField;
104 /**
105 * Manages highscores
106 */
107 KAtomicHighscores *m_highscore;
108
109 int m_moves;
110 /**
111 * Current levelset
112 */
113 LevelSet m_levelSet;
114 /**
115 * Highscore of the current level
116 */
117 int m_levelHighscore;
118 /**
119 * Number of the current level
120 */
121 int m_level;
122 /**
123 * Timer for automatic next level
124 */
125 QTimer *m_timer;
126};
127
128#endif
129