• 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
kgrlevelplayer.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 KGRLEVELPLAYER_H
19 #define KGRLEVELPLAYER_H
20 
21 #include "kgrglobals.h"
22 
23 #include <QObject>
24 #include <QList>
25 #include <QVarLengthArray>
26 
27 #include <QTime> // IDW testing
28 
29 class KGrTimer;
30 class KGrLevelGrid;
31 class KGrRuleBook;
32 class KGrView;
33 class KGrHero;
34 class KGrEnemy;
35 
36 class KRandomSequence;
37 
65 class KGrLevelPlayer : public QObject
66 {
67  Q_OBJECT
68 public:
77  KGrLevelPlayer (QObject * parent, KRandomSequence * pRandomGen);
78  ~KGrLevelPlayer();
79 
111  void init (KGrView * view,
112  KGrRecording * pRecording,
113  const bool pPlayback,
114  const bool gameFrozen);
115 
120  void prepareToPlay ();
121 
127  void pause (bool stop);
128 
134  void interruptPlayback();
135 
139  void killHero();
140 
147  void setControlMode (const int mode);
148 
158  void setHoldKeyOption (const int option);
159 
166  void setTimeScale (const int timeScale);
167 
174  void setTarget (int pointerI, int pointerJ);
175 
183  void setDirectionByKey (const Direction dirn, const bool pressed);
184 
195  Direction getDirection (int heroI, int heroJ);
196 
208  Direction getEnemyDirection (int enemyI, int enemyJ, bool leftRightSearch);
209 
223  int runnerGotGold (const int spriteId, const int i, const int j,
224  const bool hasGold, const bool lost = false);
225 
235  bool heroCaught (const int heroX, const int heroY);
236 
247  KGrEnemy * standOnEnemy (const int spriteId, const int x, const int y);
248 
261  bool bumpingFriend (const int spriteId, const Direction dirn,
262  const int gridI, const int gridJ);
263 
272  void unstackEnemy (const int spriteId,
273  const int gridI, const int gridJ,
274  const int prevEnemy);
283  void enemyReappear (int & gridI, int & gridJ);
284 
296  uchar randomByte (const uchar limit);
297 
317  void dbgControl (int code); // Authors' debugging aids.
318 
319 signals:
320  void endLevel (const int result);
321  void getMousePos (int & i, int & j);
322  void setMousePos (const int i, const int j);
323 
333  void animation (bool missed);
334 
344  void paintCell (int i, int j, char tileType);
345 
346  int makeSprite (char spriteType, int i, int j);
347 
360  void startAnimation (const int spriteId, const bool repeating,
361  const int i, const int j, const int time,
362  const Direction dirn, const AnimationType type);
363 
364  void deleteSprite (const int spriteId);
365  void gotGold (const int spriteId, const int i, const int j,
366  const bool hasGold, const bool lost);
367  void interruptDemo ();
368 
369 private slots:
391  void tick (bool missed, int scaledTime);
392 
393  void doDig (int button); // Dig using mouse-buttons.
394 
395 private:
396  QObject * game;
397  KRandomSequence * randomGen;
398  KGrLevelGrid * grid;
399  KGrRuleBook * rules;
400  KGrHero * hero;
401  int heroId;
402  QList<KGrEnemy *> enemies;
403 
404  int controlMode;
405  int holdKeyOption;
406  int levelWidth;
407  int levelHeight;
408 
409  int nuggets;
410 
411  enum PlayState {NotReady, Ready, Playing};
412  PlayState playState;
413 
414  KGrRecording * recording;
415  bool playback;
416  int recIndex;
417  int recCount;
418  int randIndex;
419 
420  int targetI; // Where the mouse is pointing.
421  int targetJ;
422 
423  Direction setDirectionByDelta (const int di, const int dj,
424  const int heroI, const int heroJ);
425  Direction direction; // Direction for the hero to take.
426  Direction newDirection; // Next direction for the hero to take.
427  KGrTimer * timer; // The time-standard for the level.
428 
429  void startDigging (Direction diggingDirection);
430  void processDugBricks (const int scaledTime);
431 
432  int digCycleTime; // Milliseconds per dig-timing cycle.
433  int digCycleCount; // Number of cycles hole is fully open.
434  int digOpeningCycles; // Cycles for brick-opening animation.
435  int digClosingCycles; // Cycles for brick-closing animation.
436  int digKillingTime; // Cycle when enemy/hero gets killed.
437 
438  int dX; // X motion for KEYBOARD + HOLD_KEY.
439  int dY; // Y motion for KEYBOARD + HOLD_KEY.
440 
441  typedef struct {
442  int id;
443  int cycleTimeLeft;
444  int digI;
445  int digJ;
446  int countdown;
447  int startTime; // IDW testing
448  } DugBrick;
449 
450  QList <DugBrick *> dugBricks;
451 
452  int reappearIndex;
453  QVector<int> reappearPos;
454  void makeReappearanceSequence();
455  bool doRecordedMove();
456  void recordInitialWaitTime (const int ms);
457  void record (const int bytes, const int n1, const int n2 = 0);
458 
459 /******************************************************************************/
460 /************************** AUTHORS' DEBUGGING AIDS **************************/
461 /******************************************************************************/
462 
463  static int playerCount;
464 
465  void bugFix(); // Turn a bug fix on/off dynamically.
466  void startLogging(); // Turn logging on/off.
467  void showFigurePositions(); // Show everybody's co-ordinates.
468  void showObjectState(); // Show an object's state.
469  void showEnemyState (int); // Show enemy's co-ordinates and state.
470 
472  QTime t; // IDW testing
473  int T; // IDW testing
474 };
475 
476 #endif // KGRLEVELPLAYER_H
KGrLevelPlayer::prepareToPlay
void prepareToPlay()
Indicate that setup is complete and the human player can start playing at any time, by moving the pointer device or pressing a key.
Definition: kgrlevelplayer.cpp:360
KGrLevelPlayer::unstackEnemy
void unstackEnemy(const int spriteId, const int gridI, const int gridJ, const int prevEnemy)
Helper function to remove an enemy from among several stacked in a cell.
Definition: kgrlevelplayer.cpp:728
KGrLevelPlayer::heroCaught
bool heroCaught(const int heroX, const int heroY)
Helper function to determine whether the hero has collided with an enemy and must lose a life (unless...
Definition: kgrlevelplayer.cpp:632
KGrLevelPlayer::endLevel
void endLevel(const int result)
KGrLevelPlayer::enemyReappear
void enemyReappear(int &gridI, int &gridJ)
Helper function to determine where an enemy should reappear after being trapped in a brick...
Definition: kgrlevelplayer.cpp:880
KGrLevelPlayer::~KGrLevelPlayer
~KGrLevelPlayer()
Definition: kgrlevelplayer.cpp:70
KGrLevelPlayer
Class to play, record and play back a level of a game.
Definition: kgrlevelplayer.h:65
KGrLevelGrid
Definition: kgrlevelgrid.h:27
KGrLevelPlayer::setHoldKeyOption
void setHoldKeyOption(const int option)
Change the keyboard click/hold option during play.
Definition: kgrlevelplayer.cpp:1175
KGrLevelPlayer::runnerGotGold
int runnerGotGold(const int spriteId, const int i, const int j, const bool hasGold, const bool lost=false)
Helper function for an enemy to pick up or drop gold or the hero to collect gold. ...
Definition: kgrlevelplayer.cpp:820
QTime
KGrLevelPlayer::pause
void pause(bool stop)
Pause or resume the gameplay in this level.
Definition: kgrlevelplayer.cpp:368
KGrLevelPlayer::interruptPlayback
void interruptPlayback()
Stop playback of a recorded level and adjust the content of the recording so that the user can contin...
Definition: kgrlevelplayer.cpp:1065
KGrLevelPlayer::animation
void animation(bool missed)
Requests the view to update animated sprites.
KGrLevelPlayer::bumpingFriend
bool bumpingFriend(const int spriteId, const Direction dirn, const int gridI, const int gridJ)
Helper function to determine whether an enemy is colliding with another enemy.
Definition: kgrlevelplayer.cpp:672
KGrHero
This class models the behaviour of the hero.
Definition: kgrrunner.h:148
Direction
Direction
Definition: kgrglobals.h:174
KGrLevelPlayer::deleteSprite
void deleteSprite(const int spriteId)
KGrLevelPlayer::getMousePos
void getMousePos(int &i, int &j)
KGrRuleBook
Definition: kgrrulebook.h:30
QObject
KGrLevelPlayer::dbgControl
void dbgControl(int code)
Implement author's debugging aids, which are activated only if the level is paused and the KConfig fi...
Definition: kgrlevelplayer.cpp:1198
KGrLevelPlayer::gotGold
void gotGold(const int spriteId, const int i, const int j, const bool hasGold, const bool lost)
KGrRecording
KGrRecording structure: contains a record of play in a KGoldrunner level.
Definition: kgrglobals.h:115
KGrLevelPlayer::setDirectionByKey
void setDirectionByKey(const Direction dirn, const bool pressed)
Set a direction for the hero to move or dig when using keyboard control.
Definition: kgrlevelplayer.cpp:440
KGrLevelPlayer::setTimeScale
void setTimeScale(const int timeScale)
Set the overall speed of gameplay.
Definition: kgrlevelplayer.cpp:1185
KGrTimer
Definition: kgrtimer.h:25
QList< KGrEnemy * >
KGrLevelPlayer::randomByte
uchar randomByte(const uchar limit)
Helper function to provide enemies with random numbers for reappearing and deciding whether to pick u...
Definition: kgrlevelplayer.cpp:925
KGrLevelPlayer::getDirection
Direction getDirection(int heroI, int heroJ)
Helper function for the hero to find his next direction when using mouse or touchpad control...
Definition: kgrlevelplayer.cpp:480
KGrLevelPlayer::KGrLevelPlayer
KGrLevelPlayer(QObject *parent, KRandomSequence *pRandomGen)
The constructor of KGrLevelPlayer.
Definition: kgrlevelplayer.cpp:38
KGrLevelPlayer::makeSprite
int makeSprite(char spriteType, int i, int j)
KGrLevelPlayer::killHero
void killHero()
If not in playback mode, add a code to the recording and kill the hero.
Definition: kgrlevelplayer.cpp:1154
KGrLevelPlayer::paintCell
void paintCell(int i, int j, char tileType)
Requests the view to display a particular type of tile at a particular cell, or make it empty and sho...
QVector< int >
kgrglobals.h
KGrLevelPlayer::setMousePos
void setMousePos(const int i, const int j)
KGrView
Definition: kgrview.h:27
KGrLevelPlayer::interruptDemo
void interruptDemo()
KGrLevelPlayer::setControlMode
void setControlMode(const int mode)
Change the input-mode during play.
Definition: kgrlevelplayer.cpp:1165
KGrLevelPlayer::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 to display an animation of a dug brick at a particular cell, cancelling and superse...
QObject::parent
QObject * parent() const
KGrLevelPlayer::getEnemyDirection
Direction getEnemyDirection(int enemyI, int enemyJ, bool leftRightSearch)
Helper function for an enemy to find his next direction, based on where the hero is and the search al...
Definition: kgrlevelplayer.cpp:621
KGrLevelPlayer::setTarget
void setTarget(int pointerI, int pointerJ)
Set a point for the hero to aim at when using mouse or touchpad control.
Definition: kgrlevelplayer.cpp:378
AnimationType
AnimationType
Definition: kgrglobals.h:203
KGrEnemy
This class models the behaviour of an enemy.
Definition: kgrrunner.h:229
KGrLevelPlayer::standOnEnemy
KGrEnemy * standOnEnemy(const int spriteId, const int x, const int y)
Helper function to determine whether the hero or an enemy is standing on an enemy's head...
Definition: kgrlevelplayer.cpp:652
KGrLevelPlayer::init
void init(KGrView *view, KGrRecording *pRecording, const bool pPlayback, const bool gameFrozen)
The main initialisation of KGrLevelPlayer.
Definition: kgrlevelplayer.cpp:100
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