1/***************************************************************************
2* KBlocks, a falling blocks game for KDE *
3* Copyright (C) 2010 Mauricio Piacentini <mauricio@tabuleiro.com> *
4* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
5* *
6* This program is free software; you can redistribute it and/or modify *
7* it under the terms of the GNU General Public License as published by *
8* the Free Software Foundation; either version 2 of the License, or *
9* (at your option) any later version. *
10***************************************************************************/
11#ifndef KBLOCKSSCENE_H
12#define KBLOCKSSCENE_H
13
14#include <QGraphicsScene>
15#include <QGraphicsSceneMouseEvent>
16#include <QString>
17
18#include <KLocale>
19#include <KGamePopupItem>
20#include <KgDifficulty>
21
22#include "KBlocksSound.h"
23#include "KBlocksGraphics.h"
24#include "KBlocksItemGroup.h"
25#include "KBlocksScore.h"
26
27#include "GameLogicInterface.h"
28
29#include "KBlocksDefine.h"
30
31class KBlocksScene : public QGraphicsScene
32{
33 Q_OBJECT
34
35 public:
36 explicit KBlocksScene(GameLogicInterface * p, int capacity = 1);
37 ~KBlocksScene();
38
39 KBlocksItemGroup* getItemGroup(int index);
40 KBlocksScore* getScoreHandler(int index);
41
42 void createGameItemGroups(int groupCount, bool snapshotMode = false);
43 void deleteGameItemGroups();
44
45 void setGamesPerLine(int count);
46 void setGameAnimEnabled(bool flag);
47 void setWaitForAllUpdate(bool flag);
48 void setUpdateInterval(int interval);
49 void setSoundsEnabled(bool enabled);
50
51 void readSettings(const QSize & viewSize);
52 void viewScaled(const QSize& newsize);
53
54 void startGame();
55 void stopGame();
56
57 void pauseGame(bool flag, bool fromUI = false);
58
59 void addScore(int gameIndex, int lineCount);
60
61 signals:
62 void scoreChanged(int index, int points, int lines, int level);
63 void isHighscore(int index, int points, int level);
64
65 private:
66 void updateDimensions();
67
68 private slots:
69 void greetPlayer();
70 void gameOverPlayer();
71 void gameOverMultiWin();
72 void gameOverMultiLose();
73
74 void showMessage(const QString& message, int ms);
75
76 void updateGame();
77 void readyForAction(int groupID);
78
79 protected:
80 void drawBackground(QPainter * painter, const QRectF & rect);
81
82 private:
83 GameLogicInterface* mpGameLogic;
84 bool mGameStarted;
85
86 KBlocksGraphics* mpGrafx;
87 KBlocksSound* mpSnd;
88
89 int mSceneGamesPerLine;
90 bool mGameAnimEnabled;
91 bool mWaitForAllUpdate;
92 bool* maGameReadySignal;
93
94 bool mSnapshotMode;
95
96 int mTopGameLevel;
97
98 int mMaxCapacity;
99 int mGroupCount;
100 KBlocksItemGroup** maGroupList;
101 KBlocksScore** maGameScoreList;
102
103 KGamePopupItem* mMessageBox;
104
105 int mUpdateInterval;
106 QTimer mUpdateTimer;
107};
108
109#endif
110
111