File indexing completed on 2024-04-21 04:01:59
0001 /* 0002 SPDX-FileCopyrightText: 1998 Andreas Wüst <AndreasWuest@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef GAMEWIDGET_H 0008 #define GAMEWIDGET_H 0009 0010 #include "levelset.h" 0011 0012 #include <QWidget> 0013 0014 class PlayField; 0015 class QGraphicsView; 0016 class QTimer; 0017 0018 class KAtomicHighscores; 0019 0020 class GameWidget : public QWidget 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 explicit GameWidget ( const QString& levelSet, QWidget *parent ); 0026 ~GameWidget() override; 0027 0028 bool setLevelSet(const QString& levelSet); 0029 0030 /** 0031 * @return levelset name 0032 */ 0033 const LevelSet& levelSet() const; 0034 0035 void enableSwitchToAnyLevel() { m_allowAnyLevelSwitch = true; } 0036 bool switchToAnyLevelAllowed() const { return m_allowAnyLevelSwitch; } 0037 0038 PlayField* playfield() { return m_playField; } 0039 0040 int currentLevel() const { return m_level; } 0041 QString currentMolecule() const; 0042 int currentScore() const { return m_moves; } 0043 int currentHighScore() const; 0044 0045 bool isNextLevelAvailable() const; 0046 bool isPrevLevelAvailable() const; 0047 0048 void saveMaxAccessibleLevel(int level); 0049 void saveLastPlayedLevel(); 0050 0051 Q_SIGNALS: 0052 void statsChanged(int level,int score,int highscore); 0053 void levelChanged(int level); 0054 0055 public Q_SLOTS: 0056 void prevLevel(); 0057 void nextLevel(); 0058 0059 void saveGame(); 0060 void loadGame(); 0061 0062 // restart current level 0063 void restartLevel(); 0064 0065 void gameOver(int moves); 0066 0067 // use this slot to update the moves continually 0068 void updateMoves(int moves); 0069 0070 void showHighscores (); 0071 0072 void moveUp(); 0073 void moveDown(); 0074 void moveLeft(); 0075 void moveRight(); 0076 private: 0077 0078 void resizeEvent( QResizeEvent* ) override; 0079 void switchToLevel (int); 0080 0081 int lastPlayedLevel() const; 0082 int maxAccessibleLevel() const; 0083 0084 /** 0085 * If on, katomic will allow user to switch to any 0086 * level even if she didn't solved it yet. 0087 */ 0088 bool m_allowAnyLevelSwitch; 0089 0090 QGraphicsView *m_view; 0091 PlayField *m_playField; 0092 /** 0093 * Manages highscores 0094 */ 0095 KAtomicHighscores *m_highscore; 0096 0097 int m_moves; 0098 /** 0099 * Current levelset 0100 */ 0101 LevelSet m_levelSet; 0102 /** 0103 * Highscore of the current level 0104 */ 0105 int m_levelHighscore; 0106 /** 0107 * Number of the current level 0108 */ 0109 int m_level; 0110 /** 0111 * Timer for automatic next level 0112 */ 0113 QTimer *m_timer; 0114 }; 0115 0116 #endif