• Skip to content
  • Skip to link menu
KDE 4.2 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 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();         // True if the game is in mouse mode.
00067     bool inEditMode();          // True if the game is in editor mode.
00068     bool isLoading();           // True if a level is being loaded.
00069 
00070     bool saveOK (bool exiting);     // Check if edits were saved.
00071 
00072     QString getTitle();     // Collection - Level NNN, Name.
00073 
00074     void setEditObj (char newEditObj);  // Set object for editor to paint.
00075 
00076     QString getDirectory (Owner o);
00077 
00078 public slots:
00079     void initGame();            // Do the game object's first painting.
00080 
00081     void startLevelOne();       // Start any game from level 1.
00082     void startAnyLevel();       // Start any game from any level.
00083     void startNextLevel();      // Start next level of current game.
00084 
00085     void setPlaySounds (bool on_off);   // Set sound enabled or disabled.
00086 
00087     void setMouseMode (bool on_off);    // Set mouse OR keyboard control.
00088     void startLevel (int startingAt, int requestedLevel);
00089     void newGame (const int lev, const int gameIndex);
00090     void startTutorial();       // Start tutorial game.
00091     void showHint();            // Show hint for current level.
00092 
00093     void showHighScores();      // Show high scores for current game.
00094 
00095     void incScore (int);        // Update the score.
00096     void herosDead();           // Hero was caught or he quit (key Q).
00097     void showHiddenLadders();       // Show hidden ladders (nuggets gone).
00098     void levelCompleted();      // Hero completed the level.
00099     void goUpOneLevel();        // Start next level.
00100     void loseNugget();          // Nugget destroyed (not collected).
00101     void heroAction (KBAction movement);// Move hero under keyboard control.
00102 
00103     void saveGame();            // Save game ID, score and level.
00104     void loadGame();            // Re-load game, score and level.
00105 
00106     void heroStep (bool climbing);  // The hero has put a foot on the floor.
00107     void heroFalls (bool startStop);    // The hero has started/stopped falling.
00108     void heroDigs();            // The hero is digging.
00109 signals:
00110     void showScore (long);      // For main window to show the score.
00111     void showLives (long);      // For main window to show lives left.
00112     void showLevel (int);       // For main window to show the level.
00113 
00114     void hintAvailable (bool);      // For main window to adjust menu text.
00115 
00116     void setEditMenu (bool);        // Enable/Disable edit menu items.
00117     void defaultEditObj();      // Set default edit-toolbar button.
00118 
00119     void markRuleType (char);       // Mark KGoldrunner/Traditional rules.
00120     void gameFreeze (bool);     // Do visual feedback in the GUI.
00121 
00122     void quitGame();            // Used for Quit option in Quick Start.
00123 
00124 private:
00125     KDialog * qs;           // Pointer to Quick Start dialog box.
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();     // Hero is dead: re-start the level.
00136     void readMousePos();        // Timed reading of mouse position.
00137     void doDig (int button);        // Dig when under mouse-button control.
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();      // Check if high score for current game.
00150 
00151     int  selectLevel (int action, int requestedLevel);
00152     int  selectedGame;
00153 
00154     void restart();         // Kickstart the game action.
00155 
00156     bool safeRename (const QString & oldName, const QString & newName);
00157 
00158 /******************************************************************************/
00159 /**************************  PLAYFIELD AND GAME DATA  *************************/
00160 /******************************************************************************/
00161 
00162 private:
00163     KGrCanvas *         view;       // Where the game is displayed.
00164     QString         systemDataDir;  // System games are stored here.
00165     QString         userDataDir;    // User games are stored here.
00166 
00167     KGrObject *     playfield[30][22];  // Array of playfield objects.
00168     char        editObjArray[30][22];   // Character-code equivalent.
00169     char        lastSaveArray[30][22];  // Copy for use in "saveOK()".
00170 
00171     int             level;      // Current play/edit level.
00172     QString         levelName;  // Level name (optional).
00173     QString         levelHint;  // Level hint (optional).
00174 
00175     long            lives;      // Lives remaining.
00176     long            score;      // Current score.
00177     long            startScore; // Score at start of level.
00178 
00179     KGrHero *           hero;       // The HERO figure !!  Yay !!!
00180     int             startI, startJ; // The hero's starting position.
00181 
00182     QList<KGrEnemy *>       enemies;    // The list of enemies.
00183     int             enemyCount; // How many enemies.
00184     KGrEnemy *          enemy;      // One of the enemies.
00185 
00186     int             nuggets;    // How many gold nuggets.
00187 
00188     bool            newLevel;   // Next level will be a new one.
00189     bool            loading;    // Stop input until it's loaded.
00190 
00191     bool            modalFreeze;    // Stop game during dialog.
00192     bool            messageFreeze;  // Stop game during message.
00193 
00194     QTimer *            mouseSampler;   // Timer for mouse tracking.
00195     QTimer *            dyingTimer; // For pause when the hero dies.
00196 
00197     int             lgHighlight;    // Row selected in "loadGame()".
00198 
00199 /******************************************************************************/
00200 /*******************************  SOUND SUPPORT *******************************/
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 /**************************  AUTHORS' DEBUGGING AIDS **************************/
00219 /******************************************************************************/
00220 
00221 public slots:
00222     void doStep();      // Do one animation step.
00223     void showFigurePositions(); // Show everybody's co-ordinates.
00224     void showHeroState();   // Show hero's co-ordinates and state.
00225     void showEnemyState (int);  // Show enemy's co-ordinates and state.
00226     void showObjectState(); // Show an object's state.
00227     void bugFix();      // Turn a bug fix on/off dynamically.
00228     void startLogging();    // Turn logging on/off.
00229 
00230 /******************************************************************************/
00231 /********************  GAME EDITOR PROPERTIES AND METHODS  ********************/
00232 /******************************************************************************/
00233 
00234 public slots:           // Slots connected to the Menu and Edit Toolbar.
00235     void createLevel();     // Set up a blank level-display for edit.
00236     void updateLevel();         // Update an existing level.
00237     void updateNext();          // Update the current level + 1.
00238     void editNameAndHint(); // Run a dialog to edit the level name and hint.
00239     bool saveLevelFile();   // Save the edited level in a text file (.grl).
00240     void moveLevelFile();   // Move level to another collection or number.
00241     void deleteLevelFile(); // Delete a level file.
00242 
00243     void editCollection (int action);
00244 
00245     void setLevel (int lev);    // Set level to be edited.
00246 
00247     void freeze();      // Stop the gameplay action.
00248     void unfreeze();        // Restart the gameplay action.
00249     void setMessageFreeze (bool);
00250 
00251 private:
00252     bool mouseMode;     // Flag to set up keyboard OR mouse control.
00253     bool editMode;      // Flag to change keyboard and mouse functions.
00254     char editObj;       // Type of object to be painted by the mouse.
00255     bool paintEditObj;      // Sets painting on/off (toggled by clicking).
00256     bool paintAltObj;       // Sets painting for the alternate object on/off
00257     int  oldI, oldJ;        // Last mouse position painted.
00258     int  editLevel;     // Level to be edited (= 0 for new level).
00259     int  heroCount;     // Can enter at most one hero.
00260     bool shouldSave;        // True if name or hint was edited.
00261 
00262 private:
00263     QString getFilePath  (Owner o, KGrCollection * colln, int lev);
00264     void loadEditLevel (int);   // Load and display an existing level for edit.
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     // Pixmaps for repainting objects as they are edited.
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);      // For mouse-click when in edit-mode.
00281     void endEdit (int);     // For mouse-release when in edit-mode.
00282 
00283 /******************************************************************************/
00284 /********************   COLLECTION PROPERTIES AND METHODS   *******************/
00285 /******************************************************************************/
00286 
00287 private:
00288 
00289 // Note that a collection of KGoldrunner levels is the same thing as a "game".
00290     QList<KGrCollection *>  collections;    // List of ALL collections.
00291 
00292     KGrCollection *     collection; // Collection currently in use.
00293     Owner           owner;      // Collection owner.
00294     int             collnIndex; // Index in collections list.
00295 
00296     void mapCollections();
00297     bool loadCollections (Owner);
00298     bool saveCollections (Owner);
00299 
00300 /******************************************************************************/
00301 /**********************    WORD-WRAPPED MESSAGE BOX    ************************/
00302 /******************************************************************************/
00303 
00304     void myMessage (QWidget * parent, const QString &title, const QString &contents);
00305 };
00306 
00307 /******************************************************************************/
00308 /**********************    CLASS TO DISPLAY THUMBNAIL   ***********************/
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);  // Draw a preview of a level.
00324 
00325 private:
00326     QByteArray levelName;
00327     QByteArray levelLayout;
00328     QLabel *   lName;               // Place to write level-name.
00329 };
00330 
00331 /******************************************************************************/
00332 /***********************    COLLECTION DATA CLASS    **************************/
00333 /******************************************************************************/
00334 
00335 // Note that a collection of KGoldrunner levels is the same thing as a "game".
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;      // Collection owner: "System" or "User".
00342     QString name;       // Collection name.
00343     QString prefix;     // Collection's filename prefix.
00344     char    settings;   // Collection rules: KGoldrunner or Traditional.
00345     int     nLevels;    // Number of levels in the collection.
00346     QString about;      // Optional text about the collection.
00347     char    skill;      // Skill level: Tutorial, Normal or Champion.
00348 };
00349 
00350 #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