File indexing completed on 2022-09-20 13:02:19

0001 /*
0002     SPDX-FileCopyrightText: 2008-2009 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDIAMOND_GAMESTATE_H
0008 #define KDIAMOND_GAMESTATE_H
0009 
0010 #include <QObject>
0011 
0012 namespace KDiamond
0013 {
0014 
0015 class GameStatePrivate;
0016 
0017 //base duration of a game in seconds
0018 const int GameDuration = 200;
0019 
0020 enum Mode {
0021     NormalGame,
0022     UntimedGame
0023 };
0024 enum State {
0025     Playing,
0026     Paused,
0027     Finished
0028 };
0029 
0030 class GameState : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     GameState();
0035     ~GameState() override;
0036 
0037     Mode mode() const;
0038     State state() const;
0039     int leftTime() const;
0040     int points() const;
0041 
0042     void setMode(Mode mode);
0043     void setState(State state);
0044 public Q_SLOTS:
0045     void addPoints(int removedDiamonds);
0046     void removePoints(int points);
0047     void resetCascadeCounter();
0048     void startNewGame();
0049     void update(bool forceRecalculation = false);
0050 Q_SIGNALS:
0051     void message(const QString &text); //text == QString() means: hide the message popup
0052     void stateChanged(KDiamond::State state); //warning: moc needs the full identifier of KDiamond::State
0053     void pointsChanged(int points);
0054     void leftTimeChanged(int seconds);
0055 protected:
0056     void timerEvent(QTimerEvent *event) override;
0057 private:
0058     GameStatePrivate *p;
0059 };
0060 
0061 }
0062 
0063 #endif // KDIAMOND_GAMESTATE_H