File indexing completed on 2024-04-14 03:59:25
0001 /****************************************************************************** 0002 * KBlocks, a falling blocks game by KDE * 0003 * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini <mauricio@tabuleiro.com> * 0004 * Zhongjie Cai <squall.leonhart.cai@gmail.com> * 0005 * Julian Helfferich <julian.helfferich@mailbox.org> * 0006 * * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 ******************************************************************************/ 0009 #ifndef KBLOCKSSCENE_H 0010 #define KBLOCKSSCENE_H 0011 0012 #include <QGraphicsSceneMouseEvent> 0013 #include <QString> 0014 0015 #include <KGamePopupItem> 0016 0017 #include "KBlocksSound.h" 0018 #include "KBlocksGraphics.h" 0019 #include "KBlocksItemGroup.h" 0020 #include "KBlocksScore.h" 0021 0022 #include "GameLogicInterface.h" 0023 0024 #include "KBlocksDefine.h" 0025 #include "SceneInterface.h" 0026 0027 class SoundInterface; 0028 class GraphicsInterface; 0029 0030 class KBlocksScene : public SceneInterface 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit KBlocksScene( 0036 GameLogicInterface *p, 0037 GraphicsInterface *graphics, 0038 SoundInterface *sound, 0039 int capacity = 1 0040 ); 0041 ~KBlocksScene() override; 0042 0043 KBlocksItemGroup *getItemGroup(int index); 0044 KBlocksScore *getScoreHandler(int index); 0045 0046 void createGameItemGroups(int groupCount, bool snapshotMode = false) override; 0047 void deleteGameItemGroups() override; 0048 0049 void setGamesPerLine(int count) override; 0050 void setGameAnimEnabled(bool flag) override; 0051 void setWaitForAllUpdate(bool flag) override; 0052 void setUpdateInterval(int interval) override; 0053 void setSoundsEnabled(bool enabled) override; 0054 0055 void readSettings() override; 0056 void loadTheme(const KGameTheme *theme) override; 0057 0058 void startGame() override; 0059 void stopGame() override; 0060 0061 void pauseGame(bool flag, bool fromUI = false) override; 0062 0063 void addScore(int gameIndex, int lineCount) override; 0064 0065 private: 0066 void updateDimensions(); 0067 0068 private Q_SLOTS: 0069 void greetPlayer(); 0070 void gameOverPlayer(); 0071 void gameOverMultiWin(); 0072 void gameOverMultiLose(); 0073 0074 void showMessage(const QString &message, int ms); 0075 0076 void updateGame(); 0077 void readyForAction(int groupID); 0078 0079 public Q_SLOTS: 0080 void playMoveSound() override; 0081 void playDropSound() override; 0082 0083 protected: 0084 void drawBackground(QPainter *painter, const QRectF &rect) override; 0085 0086 private: 0087 GameLogicInterface *mpGameLogic = nullptr; 0088 bool mGameStarted; 0089 0090 GraphicsInterface *mpGrafx = nullptr; 0091 SoundInterface *mpSnd = nullptr; 0092 0093 int mSceneGamesPerLine; 0094 bool mGameAnimEnabled; 0095 bool mWaitForAllUpdate; 0096 bool *maGameReadySignal = nullptr; 0097 0098 bool mSnapshotMode; 0099 0100 int mTopGameLevel; 0101 0102 int mMaxCapacity; 0103 int mGroupCount; 0104 KBlocksItemGroup **maGroupList = nullptr; 0105 KBlocksScore **maGameScoreList = nullptr; 0106 0107 QSizeF mBackgroundSize; 0108 0109 KGamePopupItem *mMessageBox = nullptr; 0110 0111 int mUpdateInterval; 0112 QTimer mUpdateTimer; 0113 }; 0114 0115 #endif