1 /* 2 SPDX-FileCopyrightText: 2008-2010 Stefan Majewsky <majewsky@gmx.net> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef KDIAMOND_GAME_H 8 #define KDIAMOND_GAME_H 9 10 class Diamond; 11 #include "game-state.h" 12 13 #include <QGraphicsScene> 14 class KGamePopupItem; 15 class KGameRenderer; 16 17 namespace KDiamond 18 { 19 //jobs to be done during the board update 20 enum Job { 21 SwapDiamondsJob = 1, //swap selected diamonds 22 RemoveRowsJob, //remove complete rows of diamonds and add points 23 RevokeSwapDiamondsJob, //revoke swapping of diamonds (will be requested by the RemoveRowsJob if no rows have been formed) 24 FillGapsJob, 25 UpdateAvailableMovesJob, //find and count available moves after the board has been changed 26 EndGameJob //announce end of game 27 }; 28 29 class Board; 30 } 31 32 class Game : public QGraphicsScene 33 { 34 Q_OBJECT 35 public: 36 Game(KDiamond::GameState *state, KGameRenderer *renderer); 37 public Q_SLOTS: 38 void updateGraphics(); 39 40 void clickDiamond(const QPoint &point); 41 void dragDiamond(const QPoint &point, const QPoint &direction); 42 43 void animationFinished(); 44 void message(const QString &message); 45 void stateChange(KDiamond::State state); 46 void showHint(); 47 Q_SIGNALS: 48 void boardResized(); 49 void numberMoves(int moves); 50 void pendingAnimationsFinished(); 51 protected: 52 void timerEvent(QTimerEvent *event) override; 53 void drawBackground(QPainter *painter, const QRectF &rect) override; 54 private: 55 QList<QPoint> findCompletedRows(); 56 void getMoves(); 57 private: 58 QList<KDiamond::Job> m_jobQueue; 59 QList<QPoint> m_availableMoves, m_swappingDiamonds; 60 int m_timerId; 61 62 KDiamond::Board *m_board; 63 KDiamond::GameState *m_gameState; 64 65 KGamePopupItem *m_messenger; 66 QPixmap m_backgroundPixmap; 67 }; 68 69 #endif //KDIAMOND_GAME_H 70