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