00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef KGRGAME_H
00011 #define KGRGAME_H
00012
00013
00014
00015
00016
00017
00018
00019 #define myStr toLatin1().constData
00020 #define myChar(i) at((i)).toLatin1()
00021 #define endData atEnd
00022
00023 #include <QObject>
00024 #include <QList>
00025
00026 #include <QColor>
00027 #include <QPixmap>
00028 #include <QLabel>
00029 #include <QFrame>
00030
00031 #include "kgrgameio.h"
00032 #include "kgrcanvas.h"
00033
00040 class KDialog;
00041
00042 class KGrObject;
00043 class KGrHero;
00044 class KGrEnemy;
00045 class KGrCollection;
00046 class KGrSoundBank;
00047
00048 class KGrGame : public QObject
00049 {
00050 Q_OBJECT
00051 public:
00052 KGrGame (KGrCanvas * theView, const QString &theSystemDir,
00053 const QString &theUserDir);
00054 ~KGrGame();
00055
00056 bool initCollections();
00057 KGrHero * getHero();
00058
00059 void quickStartDialog();
00060 void setInitialTheme (const QString & themeFilepath);
00061
00062 int getLevel();
00063
00064 void startPlaying();
00065
00066 bool inMouseMode();
00067 bool inEditMode();
00068 bool isLoading();
00069
00070 bool saveOK (bool exiting);
00071
00072 QString getTitle();
00073
00074 void setEditObj (char newEditObj);
00075
00076 QString getDirectory (Owner o);
00077
00078 public slots:
00079 void initGame();
00080
00081 void startLevelOne();
00082 void startAnyLevel();
00083 void startNextLevel();
00084
00085 void setPlaySounds (bool on_off);
00086
00087 void setMouseMode (bool on_off);
00088 void startLevel (int startingAt, int requestedLevel);
00089 void newGame (const int lev, const int gameIndex);
00090 void startTutorial();
00091 void showHint();
00092
00093 void showHighScores();
00094
00095 void incScore (int);
00096 void herosDead();
00097 void showHiddenLadders();
00098 void levelCompleted();
00099 void goUpOneLevel();
00100 void loseNugget();
00101 void heroAction (KBAction movement);
00102
00103 void saveGame();
00104 void loadGame();
00105
00106 void heroStep (bool climbing);
00107 void heroFalls (bool startStop);
00108 void heroDigs();
00109 signals:
00110 void showScore (long);
00111 void showLives (long);
00112 void showLevel (int);
00113
00114 void hintAvailable (bool);
00115
00116 void setEditMenu (bool);
00117 void defaultEditObj();
00118
00119 void markRuleType (char);
00120 void gameFreeze (bool);
00121
00122 void quitGame();
00123
00124 private:
00125 KDialog * qs;
00126 QString initialThemeFilepath;
00127
00128 private slots:
00129 void quickStartPlay();
00130 void quickStartNewGame();
00131 void quickStartUseMenu();
00132 void quickStartQuit();
00133
00134 private slots:
00135 void finalBreath();
00136 void readMousePos();
00137 void doDig (int button);
00138
00139 private:
00140 void setBlankLevel (bool playable);
00141 int loadLevel (int levelNo);
00142 bool readLevelData (int levelNo, LevelData & d);
00143 void changeObject (unsigned char kind, int i, int j);
00144 void createObject (KGrObject *o, char picType, int x, int y);
00145 void setTimings();
00146 void initSearchMatrix();
00147 void showTutorialMessages (int levelNo);
00148
00149 void checkHighScore();
00150
00151 int selectLevel (int action, int requestedLevel);
00152 int selectedGame;
00153
00154 void restart();
00155
00156 bool safeRename (const QString & oldName, const QString & newName);
00157
00158
00159
00160
00161
00162 private:
00163 KGrCanvas * view;
00164 QString systemDataDir;
00165 QString userDataDir;
00166
00167 KGrObject * playfield[30][22];
00168 char editObjArray[30][22];
00169 char lastSaveArray[30][22];
00170
00171 int level;
00172 QString levelName;
00173 QString levelHint;
00174
00175 long lives;
00176 long score;
00177 long startScore;
00178
00179 KGrHero * hero;
00180 int startI, startJ;
00181
00182 QList<KGrEnemy *> enemies;
00183 int enemyCount;
00184 KGrEnemy * enemy;
00185
00186 int nuggets;
00187
00188 bool newLevel;
00189 bool loading;
00190
00191 bool modalFreeze;
00192 bool messageFreeze;
00193
00194 QTimer * mouseSampler;
00195 QTimer * dyingTimer;
00196
00197 int lgHighlight;
00198
00199
00200
00201
00202 KGrSoundBank *effects;
00203 enum {
00204 GoldSound,
00205 StepSound,
00206 ClimbSound,
00207 FallSound,
00208 DigSound,
00209 LadderSound,
00210 DeathSound,
00211 CompletedSound,
00212 VictorySound,
00213 GameOverSound,
00214 NumSounds };
00215 QVector< int > fx;
00216
00217
00218
00219
00220
00221 public slots:
00222 void doStep();
00223 void showFigurePositions();
00224 void showHeroState();
00225 void showEnemyState (int);
00226 void showObjectState();
00227 void bugFix();
00228 void startLogging();
00229
00230
00231
00232
00233
00234 public slots:
00235 void createLevel();
00236 void updateLevel();
00237 void updateNext();
00238 void editNameAndHint();
00239 bool saveLevelFile();
00240 void moveLevelFile();
00241 void deleteLevelFile();
00242
00243 void editCollection (int action);
00244
00245 void setLevel (int lev);
00246
00247 void freeze();
00248 void unfreeze();
00249 void setMessageFreeze (bool);
00250
00251 private:
00252 bool mouseMode;
00253 bool editMode;
00254 char editObj;
00255 bool paintEditObj;
00256 bool paintAltObj;
00257 int oldI, oldJ;
00258 int editLevel;
00259 int heroCount;
00260 bool shouldSave;
00261
00262 private:
00263 QString getFilePath (Owner o, KGrCollection * colln, int lev);
00264 void loadEditLevel (int);
00265 void initEdit();
00266 void deleteLevel();
00267 void insertEditObj (int, int, char object);
00268 void setEditableCell (int, int, char);
00269 void showEditLevel();
00270 bool reNumberLevels (int, int, int, int);
00271 bool ownerOK (Owner o);
00272
00273
00274 QPixmap digpix[10];
00275 QPixmap brickbg, fbrickbg;
00276 QPixmap freebg, nuggetbg, polebg, betonbg, ladderbg, hladderbg;
00277 QPixmap edherobg, edenemybg;
00278
00279 private slots:
00280 void doEdit (int);
00281 void endEdit (int);
00282
00283
00284
00285
00286
00287 private:
00288
00289
00290 QList<KGrCollection *> collections;
00291
00292 KGrCollection * collection;
00293 Owner owner;
00294 int collnIndex;
00295
00296 void mapCollections();
00297 bool loadCollections (Owner);
00298 bool saveCollections (Owner);
00299
00300
00301
00302
00303
00304 void myMessage (QWidget * parent, const QString &title, const QString &contents);
00305 };
00306
00307
00308
00309
00310
00311 class KGrThumbNail : public QFrame
00312 {
00313 public:
00314 explicit KGrThumbNail (QWidget *parent = 0, const char *name = 0);
00315 void setLevelData (const QString& dir, const QString& prefix, int level, QLabel * sln);
00316
00317 static QColor backgroundColor;
00318 static QColor brickColor;
00319 static QColor ladderColor;
00320 static QColor poleColor;
00321
00322 protected:
00323 void paintEvent (QPaintEvent * event);
00324
00325 private:
00326 QByteArray levelName;
00327 QByteArray levelLayout;
00328 QLabel * lName;
00329 };
00330
00331
00332
00333
00334
00335
00336 class KGrCollection
00337 {
00338 public:
00339 KGrCollection (Owner o, const QString & n, const QString & p,
00340 const char s, int nl, const QString & a, const char sk);
00341 Owner owner;
00342 QString name;
00343 QString prefix;
00344 char settings;
00345 int nLevels;
00346 QString about;
00347 char skill;
00348 };
00349
00350 #endif