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

kapman

  • sources
  • kde-4.14
  • kdegames
  • kapman
game.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
3  * Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef GAME_H
20 #define GAME_H
21 
22 #include "maze.h"
23 #include "kapman.h"
24 #include "ghost.h"
25 #include "bonus.h"
26 
27 #include <QPointF>
28 #include <QTimer>
29 #include <QKeyEvent>
30 #include <KgSound>
31 
35 class Game : public QObject {
36 
37  Q_OBJECT
38 
39  public :
41  static qreal s_durationRatio;
42 
44  static int s_preyStateDuration;
45 
47  static int s_bonusDuration;
48 
49  private :
50 
52  static const int FPS;
53 
55  enum State {
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_bonusTimer;
71 
73  QTimer* m_preyTimer;
74 
76  Maze* m_maze;
77 
79  Kapman* m_kapman;
80 
82  QList<Ghost*> m_ghosts;
83 
85  Bonus *m_bonus;
86 
88  bool m_isCheater;
89 
91  int m_lives;
92 
94  long m_points;
95 
97  int m_level;
98 
100  int m_nbEatenGhosts;
101 
103  bool m_soundEnabled;
104 
105  KgSound m_soundGameOver;
106  KgSound m_soundGhost;
107  KgSound m_soundGainLife;
108  KgSound m_soundEnergizer;
109  KgSound m_soundBonus;
110  KgSound m_soundPill;
111  KgSound m_soundLevelUp;
112 
113 
114  public:
115 
119  Game();
120 
124  ~Game();
125 
129  void start();
130 
135  void pause(bool p_locked = false);
136 
141  void switchPause(bool p_locked = false);
142 
146  Maze* getMaze() const;
147 
151  Kapman* getKapman() const;
152 
156  QList<Ghost*> getGhosts () const;
157 
161  Bonus* getBonus() const;
162 
166  QTimer* getTimer() const;
167 
171  bool isPaused() const;
172 
176  bool isCheater() const;
177 
181  int getScore () const;
182 
186  int getLives() const;
187 
191  int getLevel() const;
192 
197  void setLevel(int p_level);
198 
203  void createBonus(QPointF p_position);
204 
209  void createKapman(QPointF p_position);
210 
216  void createGhost(QPointF p_position, const QString & p_imageId);
217 
223  void initMaze(const int p_nbRows, const int p_nbColumns);
224 
228  void initGhost();
229 
233  void initKapman();
234 
239  void setSoundsEnabled(bool p_enabled);
240 
241  private:
242 
246  void initCharactersPosition();
247 
252  void setTimersDuration();
253 
254  public slots:
255 
260  void keyPressEvent(QKeyEvent* p_event);
261 
265  void resumeAfterKapmanDeath();
266 
267  private slots:
268 
272  void update();
273 
277  void kapmanDeath();
278 
282  void ghostDeath(Ghost* p_ghost);
283 
288  void winPoints(Element* p_element);
289 
293  void nextLevel();
294 
298  void hideBonus();
299 
303  void endPreyState();
304 
305  signals:
306 
310  void gameStarted();
311 
316  void gameOver(const bool p_unused);
317 
322  void levelStarted(const bool p_newLevel);
323 
329  void pauseChanged(const bool p_pause, const bool p_fromUser);
330 
336  void elementEaten(const qreal p_x, const qreal p_y);
337 
341  void bonusOn();
342 
346  void bonusOff();
347 
352  void levelChanged( unsigned int p_level );
353 
358  void scoreChanged( unsigned int p_score );
359 
364  void livesChanged( unsigned int p_lives );
365 
366 
374  void pointsToDisplay(long p_wonPoints, qreal p_xPos, qreal p_yPos);
375 };
376 
377 #endif
378 
Game::getScore
int getScore() const
Definition: game.cpp:192
Game::setSoundsEnabled
void setSoundsEnabled(bool p_enabled)
Enables / disables the sounds.
Definition: game.cpp:248
Game::initKapman
void initKapman()
Initializes a Kapman.
Bonus
This class represents a Bonus for Kapman.
Definition: bonus.h:29
Game::getTimer
QTimer * getTimer() const
Definition: game.cpp:176
Game::start
void start()
Starts the Game.
Definition: game.cpp:135
Game::getGhosts
QList< Ghost * > getGhosts() const
Definition: game.cpp:172
Game::getKapman
Kapman * getKapman() const
Definition: game.cpp:168
Game::resumeAfterKapmanDeath
void resumeAfterKapmanDeath()
Resumes the Game after the Kapman death.
Definition: game.cpp:383
Game::createBonus
void createBonus(QPointF p_position)
Create the new Bonus.
Definition: game.cpp:232
QPointF
Game::setLevel
void setLevel(int p_level)
Sets the level to the given number.
Definition: game.cpp:203
Game::initMaze
void initMaze(const int p_nbRows, const int p_nbColumns)
Initializes a Maze.
Definition: game.cpp:244
Game::initGhost
void initGhost()
Initializes a Ghost.
Ghost
This class represents a Ghost for kapman.
Definition: ghost.h:29
Game::levelStarted
void levelStarted(const bool p_newLevel)
Emitted when a level begins, if level up or if a life has been lost.
Game::bonusOn
void bonusOn()
Emitted when the Bonus has to be displayed.
QTimer
Game::getLives
int getLives() const
Definition: game.cpp:195
Game::pauseChanged
void pauseChanged(const bool p_pause, const bool p_fromUser)
Emitted when the pause state has changed.
QObject
Game::isCheater
bool isCheater() const
Definition: game.cpp:188
maze.h
Game
This class manages the game main loop : it regularly checks the key press events, computes the charac...
Definition: game.h:35
kapman.h
Game::gameStarted
void gameStarted()
Emitted when the Game is started.
Game::createKapman
void createKapman(QPointF p_position)
Create the new Kapman.
Definition: game.cpp:236
Game::bonusOff
void bonusOff()
Emitted when the Bonus has to disappear.
Game::s_bonusDuration
static int s_bonusDuration
Timer duration for bonus apparition in medium difficulty.
Definition: game.h:47
Game::getLevel
int getLevel() const
Definition: game.cpp:199
Game::createGhost
void createGhost(QPointF p_position, const QString &p_imageId)
Create the new Ghost.
Definition: game.cpp:240
QString
QList
bonus.h
Element
This class describes the common characteristics and behaviour of any game Element (character or item)...
Definition: element.h:30
Game::s_preyStateDuration
static int s_preyStateDuration
Timer duration for prey state in medium difficulty.
Definition: game.h:44
Game::s_durationRatio
static qreal s_durationRatio
Ratio which modify the timers function of the difficulty.
Definition: game.h:41
Game::pointsToDisplay
void pointsToDisplay(long p_wonPoints, qreal p_xPos, qreal p_yPos)
Emitted when a ghost or a bonus is eaten.
Game::livesChanged
void livesChanged(unsigned int p_lives)
Emitted when the lives have changed.
QKeyEvent
Game::switchPause
void switchPause(bool p_locked=false)
Pauses / unpauses the game.
Definition: game.cpp:153
ghost.h
Game::isPaused
bool isPaused() const
Definition: game.cpp:184
Game::levelChanged
void levelChanged(unsigned int p_level)
Emitted when the level have changed.
Game::getBonus
Bonus * getBonus() const
Definition: game.cpp:228
Game::elementEaten
void elementEaten(const qreal p_x, const qreal p_y)
Emitted when an Element has been eaten.
Game::scoreChanged
void scoreChanged(unsigned int p_score)
Emitted when the score have changed.
Game::keyPressEvent
void keyPressEvent(QKeyEvent *p_event)
Manages the key press events.
Definition: game.cpp:293
Game::getMaze
Maze * getMaze() const
Definition: game.cpp:180
Kapman
This class represents the main character of the game.
Definition: kapman.h:26
Game::pause
void pause(bool p_locked=false)
Pauses the Game.
Definition: game.cpp:142
Maze
This class represents the Maze of the game.
Definition: maze.h:31
Game::gameOver
void gameOver(const bool p_unused)
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:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapman

Skip menu "kapman"
  • Main Page
  • 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