• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrrunner.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2009 Ian Wadham <iandw.au@gmail.com> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16  ****************************************************************************/
17 
18 #ifndef KGRRUNNER_H
19 #define KGRRUNNER_H
20 
21 #include "kgrglobals.h"
22 
23 #include <QObject>
24 #include <QTime> // IDW
25 
26 class KGrLevelPlayer;
27 class KGrLevelGrid;
28 class KGrRuleBook;
29 
30 enum Situation {NotTimeYet, CaughtInBrick, MidCell, EndCell};
31 
35 class KGrRunner : public QObject
36 {
37  Q_OBJECT
38 public:
53  KGrRunner (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
54  int i, int j, const int pSpriteId,
55  KGrRuleBook * pRules, const int startDelay);
56  virtual ~KGrRunner();
57 
68  inline int whereAreYou (int & x, int & y) {
69  x = gridX; y = gridY; return pointsPerCell; }
70 
71 signals:
77  void incScore (const int n);
78 
91  void startAnimation (const int spriteId, const bool repeating,
92  const int i, const int j, const int time,
93  const Direction dirn, const AnimationType type);
94 
95 protected:
96  KGrLevelPlayer * levelPlayer;
97  KGrLevelGrid * grid;
98  KGrRuleBook * rules;
99 
100  int spriteId;
101 
102  int gridI;
103  int gridJ;
104  int gridX;
105  int gridY;
106  int deltaX;
107  int deltaY;
108 
109  int pointCtr;
110  int pointsPerCell;
111  bool turnAnywhere;
112 
113  void getRules();
114 
115  Situation situation (const int scaledTime);
116  char nextCell();
117  bool setNextMovement (const char spriteType,
118  const char cellType,
119  Direction & dir,
120  AnimationType & anim, int & interval);
121 
122  bool falling;
123  Direction currDirection;
124  AnimationType currAnimation;
125 
126  int runTime; // Time interval for hero/enemy running.
127  int fallTime; // Time interval for hero/enemy falling.
128  int enemyFallTime; // Time interval for enemy falling.
129  int trapTime; // Time interval for which an enemy can
130  // stay trapped in a brick.
131 
132  int interval; // The runner's current time interval.
133  int timeLeft; // Time till the runner's next action.
134 
135  bool leftRightSearch; // KGoldrunner-rules enemy search-mode.
136 
137  QTime t; // IDW
138 };
139 
140 
148 class KGrHero : public KGrRunner
149 {
150  Q_OBJECT
151 public:
168  KGrHero (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
169  int i, int j, int pSpriteId, KGrRuleBook * pRules);
170  ~KGrHero();
171 
188  HeroStatus run (const int scaledTime);
189 
200  bool dig (const Direction dirn, int & digI, int & digJ);
201 
207  inline void setNuggets (const int nGold) { nuggets = nGold; }
208 
212  void showState();
213 
214 signals:
215  void soundSignal (const int n, const bool onOff = true);
216 private:
217  int nuggets; // Number of gold pieces remaining.
218 };
219 
220 
229 class KGrEnemy : public KGrRunner
230 {
231  Q_OBJECT
232 public:
248  KGrEnemy (KGrLevelPlayer * pLevelPlayer, KGrLevelGrid * pGrid,
249  int i, int j, int pSpriteId, KGrRuleBook * pRules);
250  ~KGrEnemy();
251 
268  void run (const int scaledTime);
269 
274  inline Direction direction() { return (currDirection); }
275 
279  inline int getPrevInCell() { return (prevInCell); }
280 
286  inline void setPrevInCell (const int prevEnemy) {
287  prevInCell = prevEnemy; }
288 
292  inline bool isFalling() { return falling; }
293 
297  void showState();
298 
299 private:
300  char rulesType; // Rules type and enemy search method.
301 
302  int nuggets; // Number of gold pieces an enemy holds.
303  int birthI; // Enemy's starting position (used in
304  int birthJ; // KGoldrunner rules for re-birth).
305  int prevInCell; // ID of previous enemy in cell or -1.
306 
307  void dropGold();
308  void checkForGold();
309  void dieAndReappear();
310 
311  void reserveCell (const int i, const int j);
312  void releaseCell (const int i, const int j);
313 };
314 
315 #endif // KGRRUNNER_H
KGrHero::KGrHero
KGrHero(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, int pSpriteId, KGrRuleBook *pRules)
The constructor of the KGrHero class.
Definition: kgrrunner.cpp:198
HeroStatus
HeroStatus
Definition: kgrglobals.h:219
KGrRunner::turnAnywhere
bool turnAnywhere
Definition: kgrrunner.h:111
KGrEnemy::setPrevInCell
void setPrevInCell(const int prevEnemy)
Sets the ID of an enemy who already occupied the same cell (or -1).
Definition: kgrrunner.h:286
KGrRunner::t
QTime t
Definition: kgrrunner.h:137
KGrRunner::trapTime
int trapTime
Definition: kgrrunner.h:129
KGrRunner::getRules
void getRules()
Definition: kgrrunner.cpp:72
KGrHero::soundSignal
void soundSignal(const int n, const bool onOff=true)
KGrLevelPlayer
Class to play, record and play back a level of a game.
Definition: kgrlevelplayer.h:65
KGrLevelGrid
Definition: kgrlevelgrid.h:27
Situation
Situation
Definition: kgrrunner.h:30
KGrRunner::pointCtr
int pointCtr
Definition: kgrrunner.h:109
KGrEnemy::KGrEnemy
KGrEnemy(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, int pSpriteId, KGrRuleBook *pRules)
The constructor of the KGrEnemy class.
Definition: kgrrunner.cpp:354
KGrEnemy::isFalling
bool isFalling()
Returns true if the enemy is falling.
Definition: kgrrunner.h:292
KGrRunner::enemyFallTime
int enemyFallTime
Definition: kgrrunner.h:128
QTime
KGrRunner::pointsPerCell
int pointsPerCell
Definition: kgrrunner.h:110
KGrRunner::runTime
int runTime
Definition: kgrrunner.h:126
KGrRunner::gridI
int gridI
Definition: kgrrunner.h:102
KGrRunner::grid
KGrLevelGrid * grid
Definition: kgrrunner.h:97
KGrHero
This class models the behaviour of the hero.
Definition: kgrrunner.h:148
Direction
Direction
Definition: kgrglobals.h:174
MidCell
Definition: kgrrunner.h:30
CaughtInBrick
Definition: kgrrunner.h:30
KGrRunner::~KGrRunner
virtual ~KGrRunner()
Definition: kgrrunner.cpp:68
KGrRuleBook
Definition: kgrrulebook.h:30
QObject
KGrRunner::situation
Situation situation(const int scaledTime)
Definition: kgrrunner.cpp:82
KGrHero::run
HeroStatus run(const int scaledTime)
Makes the hero run, under control of a pointer or the keyboard and guided by the layout of the grid...
Definition: kgrrunner.cpp:214
KGrEnemy::getPrevInCell
int getPrevInCell()
Returns the ID of an enemy who already occupied the same cell (or -1).
Definition: kgrrunner.h:279
KGrRunner::gridY
int gridY
Definition: kgrrunner.h:105
KGrRunner::deltaX
int deltaX
Definition: kgrrunner.h:106
KGrRunner::startAnimation
void startAnimation(const int spriteId, const bool repeating, const int i, const int j, const int time, const Direction dirn, const AnimationType type)
Requests the view-object to display an animation of a runner at a particular cell, cancelling and superseding any current animation.
KGrRunner::currDirection
Direction currDirection
Definition: kgrrunner.h:123
KGrRunner::whereAreYou
int whereAreYou(int &x, int &y)
Returns the exact position of a runner (in grid-points or cell sub-divisions) and the number of grid-...
Definition: kgrrunner.h:68
KGrRunner::fallTime
int fallTime
Definition: kgrrunner.h:127
KGrRunner::gridX
int gridX
Definition: kgrrunner.h:104
KGrHero::showState
void showState()
Implements the author's debugging aid that shows the hero's state.
Definition: kgrrunner.cpp:344
KGrRunner::falling
bool falling
Definition: kgrrunner.h:122
KGrRunner::KGrRunner
KGrRunner(KGrLevelPlayer *pLevelPlayer, KGrLevelGrid *pGrid, int i, int j, const int pSpriteId, KGrRuleBook *pRules, const int startDelay)
The constructor of the KGrRunner virtual class.
Definition: kgrrunner.cpp:27
KGrEnemy::direction
Direction direction()
Returns the direction in which the enemy is running: used for avoiding collisions with other enemies...
Definition: kgrrunner.h:274
KGrRunner
This class provides the shared features of all runners (hero and enemies).
Definition: kgrrunner.h:35
KGrHero::setNuggets
void setNuggets(const int nGold)
Tells the hero how many gold nuggets are remaining.
Definition: kgrrunner.h:207
KGrRunner::timeLeft
int timeLeft
Definition: kgrrunner.h:133
EndCell
Definition: kgrrunner.h:30
KGrEnemy::~KGrEnemy
~KGrEnemy()
Definition: kgrrunner.cpp:374
KGrRunner::incScore
void incScore(const int n)
Requests the KGoldrunner game to add to the human player's score.
KGrHero::dig
bool dig(const Direction dirn, int &digI, int &digJ)
Decides whether the hero can dig as is required by pressing a key or a mouse-button.
Definition: kgrrunner.cpp:305
KGrRunner::nextCell
char nextCell()
Definition: kgrrunner.cpp:113
kgrglobals.h
KGrRunner::setNextMovement
bool setNextMovement(const char spriteType, const char cellType, Direction &dir, AnimationType &anim, int &interval)
Definition: kgrrunner.cpp:121
KGrHero::~KGrHero
~KGrHero()
Definition: kgrrunner.cpp:210
NotTimeYet
Definition: kgrrunner.h:30
KGrEnemy::showState
void showState()
Implements the author's debugging aid that shows the enemy's state.
Definition: kgrrunner.cpp:610
KGrEnemy::run
void run(const int scaledTime)
Makes an enemy run, guided by the position of the hero and the layout of the grid.
Definition: kgrrunner.cpp:378
KGrRunner::leftRightSearch
bool leftRightSearch
Definition: kgrrunner.h:135
KGrRunner::rules
KGrRuleBook * rules
Definition: kgrrunner.h:98
KGrRunner::gridJ
int gridJ
Definition: kgrrunner.h:103
KGrRunner::spriteId
int spriteId
Definition: kgrrunner.h:100
KGrRunner::levelPlayer
KGrLevelPlayer * levelPlayer
Definition: kgrrunner.h:96
AnimationType
AnimationType
Definition: kgrglobals.h:203
KGrEnemy
This class models the behaviour of an enemy.
Definition: kgrrunner.h:229
KGrRunner::deltaY
int deltaY
Definition: kgrrunner.h:107
KGrRunner::interval
int interval
Definition: kgrrunner.h:132
KGrRunner::currAnimation
AnimationType currAnimation
Definition: kgrrunner.h:124
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal