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

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrgame.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2003 Marco Krüger <grisuji@gmx.de> *
3  * Copyright 2003 Ian Wadham <iandw.au@gmail.com> *
4  * Copyright 2009 Ian Wadham <iandw.au@gmail.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 KGRGAME_H
21 #define KGRGAME_H
22 
23 #include "kgrglobals.h"
24 
25 #include <QObject>
26 #include <QList>
27 #include <QVector>
28 
34 class KGrView;
35 class KGrScene;
36 class KDialog;
37 
38 class KGrSounds;
39 
40 class KGrEditor;
41 class KGrLevelPlayer;
42 class KRandomSequence;
43 class QTimer;
44 
45 class KGrGame : public QObject
46 {
47 Q_OBJECT
48 public:
49  KGrGame (KGrView * theView,
50  const QString & theSystemDir, const QString & theUserDir);
51  ~KGrGame();
52 
53  bool initGameLists();
54 
55  void setInitialTheme (const QString & themeFilepath);
56 
57  bool inEditMode(); // True if the game is in editor mode.
58 
59  bool saveOK(); // Check if edits were saved.
60 
61  // Flags to control author's debugging aids.
62  static bool bugFix;
63  static bool logging;
64 
65 public slots:
66  void initGame(); // Do the game object's first painting.
67 
68  void gameActions (const int action);
69  void editActions (const int action);
70  void editToolbarActions (const int action);
71  void settings (const int action);
72 
73  void kbControl (const int dirn, const bool pressed = true);
74 
75  void incScore (const int n); // Update the score.
76 
77  // Play or stop sound. Default is play: only FallSound can be stopped.
78  void playSound (const int n, const bool onOff = true);
79 
80 private:
81  void quickStartDialog();
82 
83  bool modeSwitch (const int action,
84  int & selectedGame, int & selectedLevel);
85  bool selectGame (const SelectAction slAction,
86  int & selectedGame, int & selectedLevel);
87 
88  void toggleSoundsOnOff (const int action); // Enable or disable sounds.
89 
90  // Set mouse, keyboard or laptop-hybrid control of the hero.
91  void setControlMode (const int mode);
92  void setHoldKeyOption (const int option);
93  void setTimeScale (const int action);
94 
95  void newGame (const int lev, const int gameIndex);
96  void runReplay (const int action,
97  const int selectedGame, const int selectedLevel);
98  bool startDemo (const Owner demoOwner, const QString & pPrefix,
99  const int levelNo);
100  void runNextDemoLevel();
101  void finishDemo();
102 
103 private slots:
104  void interruptDemo();
105 
106 private:
107  void startInstantReplay();
108  void replayLastLevel();
109 
110  void showHint(); // Show hint for current level.
111 
112  QString getTitle(); // Collection - Level NNN, Name.
113 
114  void showHighScores(); // Show high scores for current game.
115 
116  void freeze (const bool userAction, const bool on_off);
117 
118  QString getDirectory (Owner o);
119 
120  void herosDead(); // Hero was caught or he quit (key Q).
121  void levelCompleted(); // Hero completed the level.
122 
123  // Save game ID, score and level.
124  void saveGame();
125 
126  // Select a saved game, score and level.
127  bool selectSavedGame (int & selectedGame, int & selectedLevel);
128 
129  // Load and run a saved game, score and level.
130  void loadGame (const int index, const int lev);
131 
132  QString loadedData;
133 
134 private slots:
135  void endLevel (const int result); // Hero completed the level or he died.
136 
137  void finalBreath(); // Hero is dead: end the death-scene.
138  void repeatLevel(); // Hero is dead: repeat the level.
139  void goUpOneLevel(); // Start next level.
140 
141 signals:
142  // These signals go to the GUI in most cases.
143  void showScore (long); // For main window to show the score.
144  void showLives (long); // For main window to show lives left.
145 
146  void hintAvailable (bool); // For main window to adjust menu text.
147 
148  void setEditMenu (bool); // Enable/Disable edit menu items.
149 
150  void gameFreeze (bool); // Do visual feedback in the GUI.
151 
152  void quitGame(); // Used for Quit option in Quick Start.
153 
154  // Used to set/clear toggle actions and enable/disable actions.
155  void setToggle (const char * actionName, const bool onOff);
156  void setAvail (const char * actionName, const bool onOff);
157 
158 private:
159  KDialog * qs; // Pointer to Quick Start dialog box.
160  QString initialThemeFilepath;
161 
162 private slots:
163  void quickStartPlay();
164  void quickStartNewGame();
165  void quickStartUseMenu();
166  void quickStartQuit();
167 
168 private:
169  bool playLevel (const Owner fileOwner, const QString & prefix,
170  const int levelNo, const bool newLevel);
171  void setupLevelPlayer();
172  void showTutorialMessages (int levelNo);
173  void setPlayback (const bool onOff);
174 
175  void checkHighScore(); // Check if high score for current game.
176 
177  int selectedGame;
178 
179 /******************************************************************************/
180 /************************** PLAYFIELD AND GAME DATA *************************/
181 /******************************************************************************/
182 
183  KRandomSequence * randomGen; // Random number generator.
184  KGrLevelPlayer * levelPlayer; // Where the level is played.
185  KGrRecording * recording; // A recording of the play.
186  bool playback; // Play back or record?
187 
188  KGrView * view; // Where the game is displayed.
189  KGrScene * scene; // Where the graphics are.
190 
191  QString systemDataDir; // System games are stored here.
192  QString userDataDir; // User games are stored here.
193  int timeScale; // The speed of the game (2-20).
194 
195  QList<KGrGameData *> gameList; // A list of available games.
196  int gameIndex; // The index in the game-list.
197  Owner owner; // The game's owner.
198 
199  QString prefix; // Prefix for game or demo file.
200  int level; // Current play/edit/demo level.
201  int levelMax; // Last level no in game/demo.
202  QString levelName; // Level name (optional).
203  QString levelHint; // Level hint (optional).
204 
205  QString mainDemoName; // File-prefix for Main Demo.
206  GameAction demoType; // The type of replay or demo.
207  bool startupDemo; // Startup demo running?
208 
209  Owner playbackOwner; // Owner for current demo-file.
210  QString playbackPrefix; // File-prefix for current demo.
211  int playbackIndex; // Record-index for curr demo.
212  int playbackMax; // Max index for current demo.
213 
214  long lives; // Lives remaining.
215  long score; // Current score.
216  long startScore; // Score at start of level.
217 
218  bool gameFrozen; // Game stopped.
219  bool programFreeze; // Stop game during dialog, etc.
220 
221  QTimer * dyingTimer; // For pause when the hero dies.
222 
223  int lgHighlight; // Row selected in "loadGame()".
224 
225 /******************************************************************************/
226 /******************************* SOUND SUPPORT *******************************/
227 /******************************************************************************/
228  KGrSounds * effects;
229  QVector<int> fx;
230  bool soundOn;
231  bool stepsOn;
232 
233 public slots:
234  void dbgControl (const int code); // Authors' debugging aids.
235 
236 private:
237  KGrEditor * editor; // The level-editor object.
238 
239  int controlMode; // How to control the hero (e.g. K/B or mouse).
240  int holdKeyOption; // Whether K/B control is by holding or clicking keys.
241 
242 /******************************************************************************/
243 /*********************** GAME PROPERTIES AND METHODS **********************/
244 /******************************************************************************/
245 
246  bool loadGameData (Owner);
247  bool initRecordingData (const Owner fileOwner, const QString & prefix,
248  const int levelNo);
249  void saveRecording();
250  bool loadRecording (const QString & dir, const QString & prefix,
251  const int levelNo);
252  void loadSounds();
253 
254 /******************************************************************************/
255 /********************** WORD-WRAPPED MESSAGE BOX ************************/
256 /******************************************************************************/
257 
258  void myMessage (QWidget * parent, const QString &title, const QString &contents);
259 };
260 
261 #endif // KGRGAME_H
KGrGame::setToggle
void setToggle(const char *actionName, const bool onOff)
KGrGame::logging
static bool logging
Definition: kgrgame.h:63
QWidget
KGrGame::setInitialTheme
void setInitialTheme(const QString &themeFilepath)
Definition: kgrgame.cpp:413
KGrLevelPlayer
Class to play, record and play back a level of a game.
Definition: kgrlevelplayer.h:65
KGrGame::hintAvailable
void hintAvailable(bool)
KGrGame::inEditMode
bool inEditMode()
Definition: kgrgame.cpp:1146
KDialog
KGrGame::playSound
void playSound(const int n, const bool onOff=true)
Definition: kgrgame.cpp:902
QTimer
KGrGame::gameFreeze
void gameFreeze(bool)
QObject
KGrRecording
KGrRecording structure: contains a record of play in a KGoldrunner level.
Definition: kgrglobals.h:115
KGrGame::dbgControl
void dbgControl(const int code)
Definition: kgrgame.cpp:1899
KGrGame::showScore
void showScore(long)
KGrSounds
Definition: kgrsounds.h:28
KGrGame::kbControl
void kbControl(const int dirn, const bool pressed=true)
Definition: kgrgame.cpp:1332
QString
QList< KGrGameData * >
KGrGame::setAvail
void setAvail(const char *actionName, const bool onOff)
KGrGame::initGame
void initGame()
Definition: kgrgame.cpp:418
KGrGame::~KGrGame
~KGrGame()
Definition: kgrgame.cpp:123
KGrGame::showLives
void showLives(long)
KGrEditor
This class is the game-editor for KGoldrunner.
Definition: kgreditor.h:42
KGrGame::gameActions
void gameActions(const int action)
Definition: kgrgame.cpp:180
KGrGame::setEditMenu
void setEditMenu(bool)
QVector< int >
kgrglobals.h
KGrGame::bugFix
static bool bugFix
Definition: kgrgame.h:62
KGrView
Definition: kgrview.h:27
KGrGame
Definition: kgrgame.h:45
KGrGame::editToolbarActions
void editToolbarActions(const int action)
Definition: kgrgame.cpp:339
GameAction
GameAction
Definition: kgrglobals.h:152
KGrGame::saveOK
bool saveOK()
Definition: kgrgame.cpp:1529
KGrGame::KGrGame
KGrGame(KGrView *theView, const QString &theSystemDir, const QString &theUserDir)
Definition: kgrgame.cpp:86
KGrGame::editActions
void editActions(const int action)
Definition: kgrgame.cpp:253
KGrScene
The QGraphicsScene that represents KGoldrunner on the screen.
Definition: kgrscene.h:75
QObject::parent
QObject * parent() const
KGrGame::settings
void settings(const int action)
Definition: kgrgame.cpp:367
KGrGame::quitGame
void quitGame()
SelectAction
SelectAction
Definition: kgrglobals.h:60
KGrGame::incScore
void incScore(const int n)
Definition: kgrgame.cpp:896
KGrGame::initGameLists
bool initGameLists()
Definition: kgrgame.cpp:1911
Owner
Owner
Definition: kgrglobals.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • 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