The levels are now stored in the Levelset class
[ghostsoverboard] / seascene.h
1 /**************************************************************************
2         Ghosts Overboard - a game for Maemo 5
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
8         Ghosts Overboard is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23
24 #ifndef SEASCENE_H
25 #define SEASCENE_H
26
27 #include <QGraphicsScene>
28 #include<QGraphicsItemGroup>
29 #include "screenlitkeeper.h"
30 #include "level.h"
31 #include "levelset.h"
32 #include <QAction>
33 #include <QTimer>
34 #include <QSystemDeviceInfo>
35
36 using namespace QtMobility;
37
38 class SeaScene : public QGraphicsScene
39 {
40     Q_OBJECT
41 public:
42     explicit SeaScene(QObject *parent = 0);
43
44 signals:
45
46     void allGhostsPicked();
47     void pauseOn();
48     void pauseOff();
49     void vibrationActivated(bool on);
50     void minimizeRequested();
51     void fullscreenRequested();
52     void deviceJustLocked();
53
54 public slots:
55
56     /*! Places all needed items for a level to (re)start.
57     Relies on the scene size to be explicitly set to a a value that will persist troughout play.
58     @param ghosts the number of ghosts to be placed on the map
59     @param rocks the number of rocks to be placed on the map
60     @param octopuses number of octopuses to be placed on the map
61     */
62     void setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed);
63
64     void setupMap(Level level);
65
66     void spreadGhosts(int ghosts);
67
68     void removeGhost(QGraphicsItem * pGhost);
69
70     void ghostsDropped(int ghosts);
71
72     void pause (bool paused);
73
74     void vibrationActivate(bool);
75
76     void handleScreenTapped();
77
78     void about();
79
80     void restartLevel();
81
82     void nextLevel();
83
84     void restartGame();
85
86     void forcePause();
87
88     void softContinue();
89
90     void createAboutBoxItems();
91
92     void createVictoryItems();
93
94     void setItemPointersNull();
95
96     void turnPauseOn();
97
98     void handleDeviceLocked(bool isLocked);
99
100     void pollDeviceLocked();
101
102
103
104 protected:
105
106     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
107         The position is the upper left corner of a free 40x40 pixels slot.
108     */
109
110     QPointF* findRandomFreeSlot();
111
112     void createMenuItems();
113     void prepareForMenu(QGraphicsItem * pItem);
114
115     const QString ghostImageFilename_;
116     const QString rockImageFilename_;
117     const QString octopusImageFilename_;
118     const QStringList shipImageFilenames_;
119
120     QList<QPointF> freeTiles_;
121
122     int ghostsLeft_;
123
124     QList<QGraphicsItem*> movingItems_;
125
126     bool paused_;
127
128     ScreenLitKeeper screenLitKeeper_;
129
130     int menuItemCount_;
131
132     QGraphicsTextItem * pPausetextItem_;
133
134     QGraphicsTextItem * pRestartLevelItem_;
135     QGraphicsTextItem * pRestartGameItem_;
136     QGraphicsTextItem * pSettingsItem_;
137     QGraphicsTextItem * pAboutItem_;
138     QGraphicsTextItem * pQuitItem_;
139     QGraphicsTextItem * pMinimizeItem_;
140
141     QGraphicsTextItem * pVictoryCongratulationsItem_;
142     QGraphicsTextItem * pAboutBoxItem_;
143
144
145     Levelset levelset_;
146
147     int currentLevel_;
148
149
150     QAction* pVibrateAction_;
151
152     QAction* pPauseAction_;
153
154     QTimer autopauseTimer;
155
156     QSystemDeviceInfo deviceInfo_;
157
158     bool alreadyLocked_;
159
160     QTimer deviceLockPollTimer_;
161
162 };
163
164 #endif // SEASCENE_H