1/***************************************************************************
2* KBlocks, a falling blocks game for 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 <sys/time.h>
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
26class KBlocksSingleGame : public SingleGameInterface
27{
28 public:
29 explicit KBlocksSingleGame(int gameIndex, int fieldWidth = 10, int fieldHeight = 20, int showPieceCount = 2, int messagePoolSize = 256);
30 ~KBlocksSingleGame();
31
32 public:
33 KBlocksField* getField();
34
35 int getPieceCount();
36 KBlocksPiece* getPiece(int index);
37
38 bool isActive();
39 bool isGameRunning();
40
41 void setGameStandbyMode(bool flag);
42 void setGameInterval(int interval);
43 void setGameRecorder(KBlocksGameRecorder * p);
44
45 int forceUpdateGame();
46 int updateGame();
47 int punishGame(int lineCount, int punishSeed);
48
49 bool setCurrentPiece(int xPos, int yPos, int rotation);
50
51 int startGame(int seed);
52 int stopGame();
53
54 int pauseGame(bool flag);
55 int continueGame();
56
57 bool pickGameResult(int * result);
58 bool pickGameAction(int * type, int * action);
59
60 private:
61 int doUpdateGame(bool force);
62 bool runGameOneStep(int * gameResult);
63 bool checkPieceTouchGround(KBlocksPiece * p);
64 void freezePieceToField(KBlocksPiece * p);
65 int removeFieldLines();
66 void prepareNextPiece();
67
68 timeLong getMillisecOfNow();
69
70 protected:
71 KBlocksField* mpField;
72
73 int mPieceCount;
74 KBlocksPiece** mpPieceList;
75
76 private:
77 KBlocksPieceGenerator* mpPieceGenerator;
78 KBlocksGameMessage* mpGameMessage;
79 KBlocksGameRecorder* mpGameRecorder;
80
81 int mGameIndex;
82 int mCurrentGameState;
83
84 bool mStandbyMode;
85 bool mStandbyFlag;
86 int mGameInterval;
87 timeLong mGameStartTime;
88};
89
90#endif
91
92