• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

granatier

  • sources
  • kde-4.14
  • kdegames
  • granatier
  • src
game.h
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
3  * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
4  * Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef GAME_H
21 #define GAME_H
22 
23 #include "granatierglobals.h"
24 
25 #include <QObject>
26 #include <QStringList>
27 
28 class GameScene;
29 class Arena;
30 class Player;
31 class Bonus;
32 class Bomb;
33 class Block;
34 class PlayerSettings;
35 class QTimer;
36 class QKeyEvent;
37 
38 class KgSound;
39 
43 class Game : public QObject
44 {
45 
46 Q_OBJECT
47 
48 private :
49 
51  static const int FPS;
52 
54  enum State
55  {
56  RUNNING, // Game running
57  PAUSED_LOCKED, // Game paused and user is not allowed to unpause
58  PAUSED_UNLOCKED // Game paused and user is allowed to unpause
59  };
61  Q_DECLARE_FLAGS(GameStates, State)
62 
63 
64  State m_state;
65 
67  QTimer* m_timer;
68 
70  QTimer* m_roundTimer;
71 
73  QTimer* m_setRoundFinishedTimer;
74 
76  GameScene* m_gameScene;
77 
79  PlayerSettings* m_playerSettings;
80 
82  Arena* m_arena;
83 
85  QStringList m_randomArenaModeArenaList;
86 
88  QList<Player*> m_players;
89 
91  QList<Bomb*> m_bombs;
92 
94  QList<Block*> m_blocks;
95 
97  QList<Bonus*> m_bonus;
98 
100  int m_bombCount;
101 
103  int m_winPoints;
104 
106  int m_remainingTime;
107 
109  bool m_gameOver;
110 
112  QString m_strWinner;
113 
115  bool m_soundEnabled;
116 
118  bool m_wilhelmScream;
119 
120  KgSound* m_soundPutBomb;
121  KgSound* m_soundExplode;
122  KgSound* m_soundBonus;
123  KgSound* m_soundFalling;
124  KgSound* m_soundDie;
125 
126 public:
127 
132  Game(PlayerSettings* playerSettings);
133 
137  ~Game();
138 
142  void start();
143 
148  void pause(bool p_locked = false);
149 
153  void switchPause();
154 
159  void setSoundsEnabled(bool p_enabled);
160 
164  Arena* getArena() const;
165 
169  QList<Player*> getPlayers() const;
170 
174  QList<Bonus*> getBonus() const;
175 
179  QTimer* getTimer() const;
180 
184  int getRemainingTime() const;
185 
189  bool isPaused() const;
190 
194  bool getGameOver() const;
195 
199  QString getWinner() const;
200 
204  int getWinPoints() const;
205 
209  void createBonus();
210 
214  void removeBonus(Bonus* bonus);
215 
219  void blockDestroyed(const int row, const int col, Block* block);
220 
224  void removeBomb(Bomb* bomb);
225 
230  void setGameScene(GameScene* p_gameScene);
231 
232 private:
233 
237  void init();
241  void cleanUp();
242 
246  void initCharactersPosition();
247 
248 public slots:
249 
254  void keyPressEvent(QKeyEvent* p_event);
255 
260  void keyReleaseEvent(QKeyEvent* p_event);
261 
265  void setRoundFinished();
266 
275  void createBomb(Player* player, qreal x, qreal y, bool newBomb, int throwDistance);
276 
277 private slots:
278 
282  void update();
283 
287  void playerFalling();
288 
292  void playerDeath();
293 
297  void resurrectBonusTaken();
298 
302  void bombDetonated();
303 
307  void decrementRemainingRoundTime();
308 
309 signals:
310 
314  void gameStarted();
315 
319  void gameOver();
320 
326  void pauseChanged(const bool p_pause, const bool p_fromUser);
327 
331  void bombCreated(Bomb* bomb);
332 
336  void bombRemoved(Bomb* bomb);
337 
341  void infoChanged(const Granatier::Info::Type p_info);
342 };
343 
344 #endif
345 
Game::getWinner
QString getWinner() const
Definition: game.cpp:321
Game::getGameOver
bool getGameOver() const
Definition: game.cpp:316
Game::setSoundsEnabled
void setSoundsEnabled(bool p_enabled)
Enables / disables the sounds.
Definition: game.cpp:427
Bonus
This class represents a Bonus for the Player.
Definition: bonus.h:29
Game::bombRemoved
void bombRemoved(Bomb *bomb)
Emitted when a bomb was removed.
Game::getTimer
QTimer * getTimer() const
Definition: game.cpp:296
Game::switchPause
void switchPause()
Pauses / unpauses the game.
Definition: game.cpp:273
Game::getWinPoints
int getWinPoints() const
Definition: game.cpp:326
Game::start
void start()
Starts the Game.
Definition: game.cpp:248
Game::getArena
Arena * getArena() const
Definition: game.cpp:306
Game::removeBonus
void removeBonus(Bonus *bonus)
Definition: game.cpp:417
Game::~Game
~Game()
Deletes the Game instance.
Definition: game.cpp:208
Game::getPlayers
QList< Player * > getPlayers() const
Definition: game.cpp:291
QTimer
Game::setGameScene
void setGameScene(GameScene *p_gameScene)
Sets the games gamescene.
Definition: game.cpp:243
Game::pauseChanged
void pauseChanged(const bool p_pause, const bool p_fromUser)
Emitted when the pause state has changed.
QObject
Game
This class manages the game main loop : it regularly checks the key press events, computes the charac...
Definition: game.h:43
Bomb
This class describes the common characteristics and behaviour of the bomb item.
Definition: bomb.h:30
granatierglobals.h
Game::gameStarted
void gameStarted()
Emitted when the Game is started.
Game::getRemainingTime
int getRemainingTime() const
Definition: game.cpp:301
Game::removeBomb
void removeBomb(Bomb *bomb)
Removes exploded bombs from the bomb list.
Definition: game.cpp:719
Granatier::Info::Type
Type
Definition: granatierglobals.h:136
Arena
This class represents the Arena of the game.
Definition: arena.h:36
PlayerSettings
Definition: playersettings.h:27
QString
QList< Player * >
QStringList
Game::infoChanged
void infoChanged(const Granatier::Info::Type p_info)
Emitted when something to display has changed.
Game::bombCreated
void bombCreated(Bomb *bomb)
Emitted when a bomb was created.
Game::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *p_event)
Manages the key release events.
Definition: game.cpp:517
Game::getBonus
QList< Bonus * > getBonus() const
Definition: game.cpp:331
Game::blockDestroyed
void blockDestroyed(const int row, const int col, Block *block)
remove Block from list and decide to give bonus
Definition: game.cpp:739
Game::setRoundFinished
void setRoundFinished()
Checks if the round has finished and set it finished.
Definition: game.cpp:637
QKeyEvent
Game::isPaused
bool isPaused() const
Definition: game.cpp:311
Game::Game
Game(PlayerSettings *playerSettings)
Creates a new Game instance.
Definition: game.cpp:41
GameScene
This class contains all the Game elements to be drawn on the screen by the GameView instance...
Definition: gamescene.h:50
Game::createBonus
void createBonus()
Create the hidden Bonuses.
Definition: game.cpp:336
Game::keyPressEvent
void keyPressEvent(QKeyEvent *p_event)
Manages the key press events.
Definition: game.cpp:452
Game::createBomb
void createBomb(Player *player, qreal x, qreal y, bool newBomb, int throwDistance)
Creates a bomb in the Cell with the coordinates x and y or throws the bomb from that possition if the...
Definition: game.cpp:679
Player
This class represents the main character of the game.
Definition: player.h:33
Block
This class represents a block with the possibility of a bonus inside.
Definition: block.h:30
Game::pause
void pause(bool p_locked=false)
Pauses the Game.
Definition: game.cpp:257
Game::gameOver
void gameOver()
Emitted when the Game is over.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

granatier

Skip menu "granatier"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal