1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/***************************************************************************
* Copyright (C) 2003 by Ian Wadham and Marco Kr�ger *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef KGRGAME_H
#define KGRGAME_H
// Macros to smooth out the differences between TQt 1 and TQt 2 classes.
//
// "myStr" converts a TQString object to a C language "char*" character string.
// "myChar" extracts a C language character (type "char") from a TQString object.
// "endData" checks for an end-of-file condition.
//
#define myStr latin1
#define myChar(i) at((i)).latin1()
#define endData atEnd
#include <tqobject.h>
#include <tqptrlist.h>
#include <tqstring.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqdatastream.h>
#include <tqcolor.h>
/**
Sets up games and levels in KGoldrunner and controls the play.
@author Ian Wadham
*/
class KGrObject;
class KGrHero;
class KGrEnemy;
class KGrCollection;
class KGrGame : public TQObject
{
Q_OBJECT
public:
KGrGame (KGrCanvas * theView, TQString theSystemDir, TQString theUserDir);
~KGrGame();
bool initCollections();
KGrHero * getHero();
int getLevel();
void startPlaying();
bool inMouseMode(); // True if the game is in mouse mode.
bool inEditMode(); // True if the game is in editor mode.
bool isLoading(); // True if a level is being loaded.
bool saveOK (bool exiting); // Check if edits were saved.
TQString getTitle(); // Collection - Level NNN, Name.
void setEditObj (char newEditObj); // Set object for editor to paint.
TQString getFilePath (Owner o, KGrCollection * colln, int lev);
public slots:
void startLevelOne(); // Start any game from level 1.
void startAnyLevel(); // Start any game from any level.
void startNextLevel(); // Start next level of current game.
void setMouseMode (bool on_off); // Set mouse OR keyboard control.
void startLevel (int startingAt, int requestedLevel);
void newGame (const int lev, const int gameIndex);
void startTutorial(); // Start tutorial game.
void showHint(); // Show hint for current level.
void showHighScores(); // Show high scores for current game.
void incScore(int); // Update the score.
void herosDead(); // Hero was caught or he quit (key Q).
void showHiddenLadders(); // Show hidden ladders (nuggets gone).
void goUpOneLevel(); // Hero completed the level.
void loseNugget(); // Nugget destroyed (not collected).
void heroAction (KBAction movement);// Move hero under keyboard control.
void saveGame(); // Save game ID, score and level.
void loadGame(); // Re-load game, score and level.
signals:
void showScore (long); // For main window to show the score.
void showLives (long); // For main window to show lives left.
void showLevel (int); // For main window to show the level.
void hintAvailable (bool); // For main window to adjust menu text.
void setEditMenu (bool); // Enable/Disable edit menu items.
void defaultEditObj(); // Set default edit-toolbar button.
void markRuleType (char); // Mark KGoldrunner/Traditional rules.
void gameFreeze (bool); // Do visual feedback in the GUI.
private slots:
void finalBreath (); // Hero is dead: re-start the level.
void readMousePos (); // Timed reading of mouse position.
void doDig (int button); // Dig when under mouse-button control.
private:
void setBlankLevel (bool playable);
int loadLevel (int levelNo);
bool openLevelFile (int levelNo, TQFile & openlevel);
void changeObject (unsigned char kind, int i, int j);
void createObject (KGrObject *o, char picType, int x, int y);
void setTimings ();
void initSearchMatrix();
void checkHighScore(); // Check if high score for current game.
int selectLevel (int action, int requestedLevel);
int selectedGame;
void restart(); // Kickstart the game action.
/******************************************************************************/
/************************** PLAYFIELD AND GAME DATA *************************/
/******************************************************************************/
private:
KGrCanvas * view; // Where the game is displayed.
TQString systemDataDir; // System games are stored here.
TQString userDataDir; // User games are stored here.
KGrObject * playfield[30][22]; // Array of playfield objects.
char editObjArray[30][22]; // Character-code equivalent.
char lastSaveArray[30][22]; // Copy for use in "saveOK()".
int level; // Current play/edit level.
TQString levelName; // Level name (optional).
TQString levelHint; // Level hint (optional).
long lives; // Lives remaining.
long score; // Current score.
long startScore; // Score at start of level.
KGrHero * hero; // The HERO figure !! Yay !!!
int startI, startJ; // The hero's starting position.
#ifdef QT3
TQPtrList<KGrEnemy> enemies; // The list of enemies.
#else
TQPtrList<KGrEnemy> enemies; // The list of enemies.
#endif
int enemyCount; // How many enemies.
KGrEnemy * enemy; // One of the enemies.
int nuggets; // How many gold nuggets.
bool newLevel; // Next level will be a new one.
bool loading; // Stop input until it's loaded.
bool modalFreeze; // Stop game during dialog.
bool messageFreeze; // Stop game during message.
TQTimer * mouseSampler; // Timer for mouse tracking.
TQTimer * dyingTimer; // For pause when the hero dies.
int lgHighlight; // Row selected in "loadGame()".
/******************************************************************************/
/************************** AUTHORS' DEBUGGING AIDS **************************/
/******************************************************************************/
public slots:
void doStep(); // Do one animation step.
void showFigurePositions(); // Show everybody's co-ordinates.
void showHeroState(); // Show hero's co-ordinates and state.
void showEnemyState (int); // Show enemy's co-ordinates and state.
void showObjectState(); // Show an object's state.
void bugFix(); // Turn a bug fix on/off dynamically.
void startLogging(); // Turn logging on/off.
/******************************************************************************/
/******************** GAME EDITOR PROPERTIES AND METHODS ********************/
/******************************************************************************/
public slots: // Slots connected to the Menu and Edit Toolbar.
void createLevel(); // Set up a blank level-display for edit.
void updateLevel(); // Update an existing level.
void updateNext(); // Update the current level + 1.
void editNameAndHint(); // Run a dialog to edit the level name and hint.
bool saveLevelFile(); // Save the edited level in a text file (.grl).
void moveLevelFile(); // Move level to another collection or number.
void deleteLevelFile(); // Delete a level file.
void editCollection (int action);
void setLevel (int lev); // Set level to be edited.
void freeze(); // Stop the gameplay action.
void unfreeze(); // Restart the gameplay action.
void setMessageFreeze (bool);
private:
bool mouseMode; // Flag to set up keyboard OR mouse control.
bool editMode; // Flag to change keyboard and mouse functions.
char editObj; // Type of object to be painted by the mouse.
bool paintEditObj; // Sets painting on/off (toggled by clicking).
int oldI, oldJ; // Last mouse position painted.
int editLevel; // Level to be edited (= 0 for new level).
int heroCount; // Can enter at most one hero.
bool shouldSave; // True if name or hint was edited.
private:
void loadEditLevel (int); // Load and display an existing level for edit.
void initEdit();
void deleteLevel();
void insertEditObj (int, int);
void setEditableCell (int, int, char);
void showEditLevel();
bool reNumberLevels (int, int, int, int);
bool ownerOK (Owner o);
// Pixmaps for repainting objects as they are edited.
TQPixmap digpix[10];
TQPixmap brickbg, fbrickbg;
TQPixmap freebg, nuggetbg, polebg, betonbg, ladderbg, hladderbg;
TQPixmap edherobg, edenemybg;
private slots:
void doEdit(int); // For mouse-click when in edit-mode.
void endEdit(int); // For mouse-release when in edit-mode.
/******************************************************************************/
/******************** COLLECTION PROPERTIES AND METHODS *******************/
/******************************************************************************/
private:
// Note that a collection of KGoldrunner levels is the same thing as a "game".
#ifdef QT3
TQPtrList<KGrCollection> collections; // List of ALL collections.
#else
TQPtrList<KGrCollection> collections; // List of ALL collections.
#endif
KGrCollection * collection; // Collection currently in use.
Owner owner; // Collection owner.
int collnIndex; // Index in collections list.
void mapCollections();
bool loadCollections (Owner);
bool saveCollections (Owner);
/******************************************************************************/
/********************** WORD-WRAPPED MESSAGE BOX ************************/
/******************************************************************************/
void myMessage (TQWidget * parent, TQString title, TQString contents);
};
/******************************************************************************/
/********************** CLASS TO DISPLAY THUMBNAIL ***********************/
/******************************************************************************/
class KGrThumbNail : public TQFrame
{
public:
KGrThumbNail (TQWidget *parent = 0, const char *name = 0);
void setFilePath (TQString &, TQLabel *); // Set filepath and name field.
static TQColor backgroundColor;
static TQColor brickColor;
static TQColor ladderColor;
static TQColor poleColor;
protected:
void drawContents (TQPainter *); // Draw a preview of a level.
TQString filePath;
TQLabel * lName;
};
/******************************************************************************/
/*********************** COLLECTION DATA CLASS **************************/
/******************************************************************************/
// Note that a collection of KGoldrunner levels is the same thing as a "game".
class KGrCollection
{
public:
KGrCollection (Owner o, const TQString & n, const TQString & p,
const char s, int nl, const TQString & a);
Owner owner; // Collection owner: "System" or "User".
TQString name; // Collection name.
TQString prefix; // Collection's filename prefix.
char settings; // Collection rules: KGoldrunner or Traditional.
int nLevels; // Number of levels in the collection.
TQString about; // Optional text about the collection.
};
#endif
|