File indexing completed on 2024-05-05 08:05:24
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDIAMOND_GAME_H 0008 #define KDIAMOND_GAME_H 0009 0010 class Diamond; 0011 #include "game-state.h" 0012 0013 #include <QGraphicsScene> 0014 class KGamePopupItem; 0015 class KGameGraphicsViewRenderer; 0016 0017 namespace KDiamond 0018 { 0019 //jobs to be done during the board update 0020 enum Job { 0021 SwapDiamondsJob = 1, //swap selected diamonds 0022 RemoveRowsJob, //remove complete rows of diamonds and add points 0023 RevokeSwapDiamondsJob, //revoke swapping of diamonds (will be requested by the RemoveRowsJob if no rows have been formed) 0024 FillGapsJob, 0025 UpdateAvailableMovesJob, //find and count available moves after the board has been changed 0026 EndGameJob //announce end of game 0027 }; 0028 0029 class Board; 0030 } 0031 0032 class Game : public QGraphicsScene 0033 { 0034 Q_OBJECT 0035 public: 0036 Game(KDiamond::GameState *state, KGameGraphicsViewRenderer *renderer); 0037 public Q_SLOTS: 0038 void updateGraphics(); 0039 0040 void clickDiamond(const QPoint &point); 0041 void dragDiamond(const QPoint &point, const QPoint &direction); 0042 0043 void animationFinished(); 0044 void message(const QString &message); 0045 void stateChange(KDiamond::State state); 0046 void showHint(); 0047 Q_SIGNALS: 0048 void boardResized(); 0049 void numberMoves(int moves); 0050 void pendingAnimationsFinished(); 0051 protected: 0052 void timerEvent(QTimerEvent *event) override; 0053 void drawBackground(QPainter *painter, const QRectF &rect) override; 0054 private: 0055 QList<QPoint> findCompletedRows(); 0056 void getMoves(); 0057 private: 0058 QList<KDiamond::Job> m_jobQueue; 0059 QList<QPoint> m_availableMoves, m_swappingDiamonds; 0060 int m_timerId; 0061 0062 KDiamond::Board *m_board; 0063 KDiamond::GameState *m_gameState; 0064 0065 KGamePopupItem *m_messenger; 0066 QPixmap m_backgroundPixmap; 0067 }; 0068 0069 #endif //KDIAMOND_GAME_H