1 /*************************************************************************** 2 * KBlocks, a falling blocks game by KDE * 3 * Copyright (C) 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 ***************************************************************************/ 10 #ifndef KBLOCKSSINGLEGAME_H 11 #define KBLOCKSSINGLEGAME_H 12 13 #include <QObject> 14 15 #include "SingleGameInterface.h" 16 17 #include "KBlocksField.h" 18 #include "KBlocksPiece.h" 19 #include "KBlocksPieceGenerator.h" 20 #include "KBlocksGameMessage.h" 21 22 #include "KBlocksGameRecorder.h" 23 24 #include "KBlocksDefine.h" 25 26 class KBlocksSingleGame : public QObject, public SingleGameInterface 27 { 28 Q_OBJECT 29 30 public: 31 explicit KBlocksSingleGame(int gameIndex, int fieldWidth = 10, int fieldHeight = 20, int showPieceCount = 2, int messagePoolSize = 256); 32 ~KBlocksSingleGame() override; 33 34 public: 35 KBlocksField *getField() override; 36 37 int getPieceCount() override; 38 KBlocksPiece *getPiece(int index) override; 39 40 bool isActive() override; 41 bool isGameRunning() override; 42 43 void setGameStandbyMode(bool flag); 44 void setGameInterval(int interval); 45 void setGameRecorder(KBlocksGameRecorder *p); 46 47 int forceUpdateGame() override; 48 int updateGame() override; 49 int punishGame(int lineCount, int punishSeed); 50 51 bool setCurrentPiece(int xPos, int yPos, int rotation) override; 52 53 int startGame(int seed); 54 int stopGame(); 55 56 int pauseGame(bool flag); 57 int continueGame() override; 58 59 bool pickGameResult(int *result) override; 60 bool pickGameAction(int *type, int *action) override; 61 62 Q_SIGNALS: 63 void gameStopped(); 64 65 private: 66 int doUpdateGame(bool force); 67 bool runGameOneStep(int *gameResult); 68 bool checkPieceTouchGround(KBlocksPiece *p); 69 void freezePieceToField(KBlocksPiece *p); 70 int removeFieldLines(); 71 void prepareNextPiece(); 72 73 protected: 74 KBlocksField *mpField = nullptr; 75 76 int mPieceCount; 77 KBlocksPiece **mpPieceList = nullptr; 78 79 private: 80 KBlocksPieceGenerator *mpPieceGenerator = nullptr; 81 KBlocksGameMessage *mpGameMessage = nullptr; 82 KBlocksGameRecorder *mpGameRecorder = nullptr; 83 84 int mGameIndex; 85 int mCurrentGameState; 86 87 bool mStandbyMode; 88 bool mStandbyFlag; 89 int mGameInterval; 90 timeLong mGameStartTime; 91 }; 92 93 #endif 94 95