• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kgoldrunner

kgrgame.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     Copyright 2003 Marco Krüger <grisuji@gmx.de>
00003     Copyright 2003 Ian Wadham <ianw2@optusnet.com.au>
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 #ifndef KGRGAME_H
00011 #define KGRGAME_H
00012 
00013 // Macros to smooth out the differences between Qt 1 and Qt 2 classes.
00014 //
00015 // "myStr" converts a QString object to a C language "char*" character string.
00016 // "myChar" extracts a C language character (type "char") from a QString object.
00017 // "endData" checks for an end-of-file condition.
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();         // True if the game is in mouse mode.
00064     bool inEditMode();          // True if the game is in editor mode.
00065     bool isLoading();           // True if a level is being loaded.
00066 
00067     bool saveOK (bool exiting);     // Check if edits were saved.
00068 
00069     QString getTitle();     // Collection - Level NNN, Name.
00070 
00071     void setEditObj (char newEditObj);  // Set object for editor to paint.
00072 
00073     QString getDirectory (Owner o);
00074 
00075 public slots:
00076     void startLevelOne();       // Start any game from level 1.
00077     void startAnyLevel();       // Start any game from any level.
00078     void startNextLevel();      // Start next level of current game.
00079 
00080     void setMouseMode (bool on_off);    // Set mouse OR keyboard control.
00081     void startLevel (int startingAt, int requestedLevel);
00082     void newGame (const int lev = -1, const int gameIndex = -1);
00083     void startTutorial();       // Start tutorial game.
00084     void showHint();            // Show hint for current level.
00085 
00086     void showHighScores();      // Show high scores for current game.
00087 
00088     void incScore(int);         // Update the score.
00089     void herosDead();           // Hero was caught or he quit (key Q).
00090     void showHiddenLadders();       // Show hidden ladders (nuggets gone).
00091     void goUpOneLevel();        // Hero completed the level.
00092     void loseNugget();          // Nugget destroyed (not collected).
00093     void heroAction (KBAction movement);// Move hero under keyboard control.
00094 
00095     void saveGame();            // Save game ID, score and level.
00096     void loadGame();            // Re-load game, score and level.
00097 
00098 signals:
00099     void showScore (long);      // For main window to show the score.
00100     void showLives (long);      // For main window to show lives left.
00101     void showLevel (int);       // For main window to show the level.
00102 
00103     void hintAvailable (bool);      // For main window to adjust menu text.
00104 
00105     void setEditMenu (bool);        // Enable/Disable edit menu items.
00106     void defaultEditObj();      // Set default edit-toolbar button.
00107 
00108     void markRuleType (char);       // Mark KGoldrunner/Traditional rules.
00109     void gameFreeze (bool);     // Do visual feedback in the GUI.
00110 
00111     void quitGame ();           // Used for Quit option in Quick Start.
00112 
00113 private:
00114     KDialog * qs;           // Pointer to Quick Start dialog box.
00115 
00116 private slots:
00117     void quickStartPlay();
00118     void quickStartNewGame();
00119     void quickStartUseMenu();
00120     void quickStartQuit();
00121 
00122 private slots:
00123     void finalBreath ();        // Hero is dead: re-start the level.
00124     void readMousePos ();       // Timed reading of mouse position.
00125     void doDig (int button);        // Dig when under mouse-button control.
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();      // Check if high score for current game.
00138 
00139     int  selectLevel (int action, int requestedLevel);
00140     int  selectedGame;
00141 
00142     void restart();         // Kickstart the game action.
00143 
00144     bool safeRename (const QString & oldName, const QString & newName);
00145 
00146 /******************************************************************************/
00147 /**************************  PLAYFIELD AND GAME DATA  *************************/
00148 /******************************************************************************/
00149 
00150 private:
00151     KGrCanvas *         view;       // Where the game is displayed.
00152     QString         systemDataDir;  // System games are stored here.
00153     QString         userDataDir;    // User games are stored here.
00154 
00155     KGrObject *     playfield[30][22];  // Array of playfield objects.
00156     char        editObjArray[30][22];   // Character-code equivalent.
00157     char        lastSaveArray[30][22];  // Copy for use in "saveOK()".
00158 
00159     int             level;      // Current play/edit level.
00160     QString         levelName;  // Level name (optional).
00161     QString         levelHint;  // Level hint (optional).
00162 
00163     long            lives;      // Lives remaining.
00164     long            score;      // Current score.
00165     long            startScore; // Score at start of level.
00166 
00167     KGrHero *           hero;       // The HERO figure !!  Yay !!!
00168     int             startI, startJ; // The hero's starting position.
00169 
00170     QList<KGrEnemy *>       enemies;    // The list of enemies.
00171     int             enemyCount; // How many enemies.
00172     KGrEnemy *          enemy;      // One of the enemies.
00173 
00174     int             nuggets;    // How many gold nuggets.
00175 
00176     bool            newLevel;   // Next level will be a new one.
00177     bool            loading;    // Stop input until it's loaded.
00178 
00179     bool            modalFreeze;    // Stop game during dialog.
00180     bool            messageFreeze;  // Stop game during message.
00181 
00182     QTimer *            mouseSampler;   // Timer for mouse tracking.
00183     QTimer *            dyingTimer; // For pause when the hero dies.
00184 
00185     int             lgHighlight;    // Row selected in "loadGame()".
00186 
00187 /******************************************************************************/
00188 /**************************  AUTHORS' DEBUGGING AIDS **************************/
00189 /******************************************************************************/
00190 
00191 public slots:
00192     void doStep();      // Do one animation step.
00193     void showFigurePositions(); // Show everybody's co-ordinates.
00194     void showHeroState();   // Show hero's co-ordinates and state.
00195     void showEnemyState (int);  // Show enemy's co-ordinates and state.
00196     void showObjectState(); // Show an object's state.
00197     void bugFix();      // Turn a bug fix on/off dynamically.
00198     void startLogging();    // Turn logging on/off.
00199 
00200 /******************************************************************************/
00201 /********************  GAME EDITOR PROPERTIES AND METHODS  ********************/
00202 /******************************************************************************/
00203 
00204 public slots:           // Slots connected to the Menu and Edit Toolbar.
00205     void createLevel();     // Set up a blank level-display for edit.
00206     void updateLevel();         // Update an existing level.
00207     void updateNext();          // Update the current level + 1.
00208     void editNameAndHint(); // Run a dialog to edit the level name and hint.
00209     bool saveLevelFile();   // Save the edited level in a text file (.grl).
00210     void moveLevelFile();   // Move level to another collection or number.
00211     void deleteLevelFile(); // Delete a level file.
00212 
00213     void editCollection (int action);
00214 
00215     void setLevel (int lev);    // Set level to be edited.
00216 
00217     void freeze();      // Stop the gameplay action.
00218     void unfreeze();        // Restart the gameplay action.
00219     void setMessageFreeze (bool);
00220 
00221 private:
00222     bool mouseMode;     // Flag to set up keyboard OR mouse control.
00223     bool editMode;      // Flag to change keyboard and mouse functions.
00224     char editObj;       // Type of object to be painted by the mouse.
00225     bool paintEditObj;      // Sets painting on/off (toggled by clicking).
00226     bool paintAltObj;       // Sets painting for the alternate object on/off
00227     int  oldI, oldJ;        // Last mouse position painted.
00228     int  editLevel;     // Level to be edited (= 0 for new level).
00229     int  heroCount;     // Can enter at most one hero.
00230     bool shouldSave;        // True if name or hint was edited.
00231 
00232 private:
00233     QString getFilePath  (Owner o, KGrCollection * colln, int lev);
00234     void loadEditLevel (int);   // Load and display an existing level for edit.
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     // Pixmaps for repainting objects as they are edited.
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);       // For mouse-click when in edit-mode.
00251     void endEdit(int);      // For mouse-release when in edit-mode.
00252 
00253 /******************************************************************************/
00254 /********************   COLLECTION PROPERTIES AND METHODS   *******************/
00255 /******************************************************************************/
00256 
00257 private:
00258 
00259 // Note that a collection of KGoldrunner levels is the same thing as a "game".
00260     QList<KGrCollection *>  collections;    // List of ALL collections.
00261 
00262     KGrCollection *     collection; // Collection currently in use.
00263     Owner           owner;      // Collection owner.
00264     int             collnIndex; // Index in collections list.
00265 
00266     void mapCollections();
00267     bool loadCollections (Owner);
00268     bool saveCollections (Owner);
00269 
00270 /******************************************************************************/
00271 /**********************    WORD-WRAPPED MESSAGE BOX    ************************/
00272 /******************************************************************************/
00273 
00274     void myMessage (QWidget * parent, const QString &title, const QString &contents);
00275 };
00276 
00277 /******************************************************************************/
00278 /**********************    CLASS TO DISPLAY THUMBNAIL   ***********************/
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 );    // Draw a preview of a level.
00294 
00295 private:
00296     QByteArray levelName;
00297     QByteArray levelLayout;
00298     QLabel *   lName;               // Place to write level-name.
00299 };
00300 
00301 /******************************************************************************/
00302 /***********************    COLLECTION DATA CLASS    **************************/
00303 /******************************************************************************/
00304 
00305 // Note that a collection of KGoldrunner levels is the same thing as a "game".
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;      // Collection owner: "System" or "User".
00312     QString name;       // Collection name.
00313     QString prefix;     // Collection's filename prefix.
00314     char    settings;   // Collection rules: KGoldrunner or Traditional.
00315     int     nLevels;    // Number of levels in the collection.
00316     QString about;      // Optional text about the collection.
00317     char    skill;      // Skill level: Tutorial, Normal or Champion.
00318 };
00319 
00320 #endif

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal