• 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
kgrrulebook.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 KGRRULEBOOK_H
19 #define KGRRULEBOOK_H
20 
21 #include "kgrglobals.h"
22 
23 #include <QObject>
24 #include <QList>
25 
26 #include <KDebug>
27 
28 class KGrLevelGrid;
29 
30 class KGrRuleBook : public QObject
31 {
32  Q_OBJECT
33 public:
34  KGrRuleBook (QObject * parent);
35  virtual ~KGrRuleBook();
36 
37  bool variableTiming() const { return mVariableTiming; }
38  bool alwaysCollectNugget() const { return mAlwaysCollectNugget; }
39  bool runThruHole() const { return mRunThruHole; }
40  bool reappearAtTop() const { return mReappearAtTop; }
41  int reappearRow() const { return mReappearRow; }
42  int pointsPerCell() const { return mPointsPerCell; }
43  bool turnAnywhere() const { return mTurnAnywhere; }
44  bool enemiesShowGold() const { return mEnemiesShowGold; }
45 
46  void setTiming (const int enemyCount = 0);
47 
48  inline void getHeroTimes (int & runTime, int & fallTime,
49  int & enemyFallTime, int & trapTime) {
50  runTime = times.hwalk; fallTime = times.hfall;
51  enemyFallTime = times.efall; trapTime = times.ecaptive; }
52 
53  inline char getEnemyTimes (int & runTime, int & fallTime, int & trapTime) {
54  runTime = times.ewalk; fallTime = times.efall;
55  trapTime = times.ecaptive;
56  return mRules; }
57 
58  inline void getDigTimes (int & digTime, int & digCounter) {
59  digTime = 200; digCounter = times.hole; }
60 
61  virtual Direction findBestWay (const int eI, const int eJ,
62  const int hI, const int hJ,
63  KGrLevelGrid * pGrid,
64  bool leftRightSearch = true) = 0;
65 
66 protected:
67  typedef struct {
68  int hwalk;
69  int hfall;
70  int ewalk;
71  int efall;
72  int ecaptive;
73  int hole;
74  } Timing;
75 
76  char mRules;
77 
78  bool mVariableTiming;
79  bool mAlwaysCollectNugget;
80  bool mRunThruHole;
81  bool mReappearAtTop;
82  int mReappearRow;
83  int mPointsPerCell;
84  bool mTurnAnywhere;
85  bool mEnemiesShowGold;
86 
87  Timing times;
88  KGrLevelGrid * grid;
89 };
90 
91 
92 class KGrTraditionalRules : public KGrRuleBook
93 {
94  Q_OBJECT
95 public:
96  KGrTraditionalRules (QObject * parent);
97  ~KGrTraditionalRules();
98 
99  Direction findBestWay (const int eI, const int eJ,
100  const int hI, const int hJ,
101  KGrLevelGrid * pGrid,
102  bool leftRightSearch = true);
103 
104 private:
105  Direction searchUp (int eI, int eJ, int hJ);
106  Direction searchDown (int eI, int eJ, int hJ);
107  Direction getHero (int eI, int eJ, int hI);
108 
109  int distanceUp (int x, int y, int deltah);
110  int distanceDown (int x, int y, int deltah);
111  bool searchOK (int direction, int x, int y);
112  int canWalkLR (int direction, int x, int y);
113  bool willNotFall (int x, int y);
114 };
115 
116 
117 class KGrKGoldrunnerRules : public KGrRuleBook
118 {
119  Q_OBJECT
120 public:
121  KGrKGoldrunnerRules (QObject * parent);
122  ~KGrKGoldrunnerRules();
123 
124  Direction findBestWay (const int eI, const int eJ,
125  const int hI, const int hJ,
126  KGrLevelGrid * pGrid,
127  bool leftRightSearch = true);
128 
129 private:
130  Direction findWayUp (const int eI, const int eJ);
131  Direction findWayDown (const int eI, const int eJ);
132  Direction findWayLeft (const int eI, const int eJ);
133  Direction findWayRight (const int eI, const int eJ);
134 };
135 
136 
137 class KGrScavengerRules : public KGrRuleBook
138 {
139  Q_OBJECT
140 public:
141  KGrScavengerRules (QObject * parent);
142  ~KGrScavengerRules();
143 
144  Direction findBestWay (const int eI, const int eJ,
145  const int hI, const int hJ,
146  KGrLevelGrid * pGrid,
147  bool leftRightSearch = true);
148 };
149 
150 #endif // KGRRULEBOOK_H
KGrRuleBook::Timing::efall
int efall
Definition: kgrrulebook.h:71
KGrScavengerRules::KGrScavengerRules
KGrScavengerRules(QObject *parent)
Definition: kgrrulebook.cpp:655
KGrRuleBook::reappearRow
int reappearRow() const
Definition: kgrrulebook.h:41
KGrKGoldrunnerRules::findBestWay
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
Definition: kgrrulebook.cpp:478
KGrLevelGrid
Definition: kgrlevelgrid.h:27
KGrRuleBook::KGrRuleBook
KGrRuleBook(QObject *parent)
Definition: kgrrulebook.cpp:23
KGrRuleBook::alwaysCollectNugget
bool alwaysCollectNugget() const
Definition: kgrrulebook.h:38
KGrRuleBook::runThruHole
bool runThruHole() const
Definition: kgrrulebook.h:39
KGrRuleBook::Timing::hfall
int hfall
Definition: kgrrulebook.h:69
KGrRuleBook::getHeroTimes
void getHeroTimes(int &runTime, int &fallTime, int &enemyFallTime, int &trapTime)
Definition: kgrrulebook.h:48
KGrKGoldrunnerRules::KGrKGoldrunnerRules
KGrKGoldrunnerRules(QObject *parent)
Definition: kgrrulebook.cpp:455
KGrRuleBook::mRunThruHole
bool mRunThruHole
Enemy can run L/R through dug hole.
Definition: kgrrulebook.h:80
KGrRuleBook::~KGrRuleBook
virtual ~KGrRuleBook()
Definition: kgrrulebook.cpp:36
KGrRuleBook::mPointsPerCell
int mPointsPerCell
Number of points in each grid-cell.
Definition: kgrrulebook.h:83
KGrRuleBook::mAlwaysCollectNugget
bool mAlwaysCollectNugget
Enemies always collect nuggets.
Definition: kgrrulebook.h:79
Direction
Direction
Definition: kgrglobals.h:174
KGrRuleBook::getDigTimes
void getDigTimes(int &digTime, int &digCounter)
Definition: kgrrulebook.h:58
KGrRuleBook::Timing::hole
int hole
Definition: kgrrulebook.h:73
KGrRuleBook::variableTiming
bool variableTiming() const
Definition: kgrrulebook.h:37
KGrTraditionalRules::findBestWay
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
Definition: kgrrulebook.cpp:84
KGrRuleBook::reappearAtTop
bool reappearAtTop() const
Definition: kgrrulebook.h:40
KGrRuleBook
Definition: kgrrulebook.h:30
QObject
KGrRuleBook::mReappearRow
int mReappearRow
Row where enemies reappear.
Definition: kgrrulebook.h:82
KGrRuleBook::mRules
char mRules
The type of rules and enemy search method.
Definition: kgrrulebook.h:76
KGrRuleBook::times
Timing times
Definition: kgrrulebook.h:87
KGrRuleBook::mReappearAtTop
bool mReappearAtTop
Enemies reborn at top of screen.
Definition: kgrrulebook.h:81
KGrScavengerRules::~KGrScavengerRules
~KGrScavengerRules()
Definition: kgrrulebook.cpp:674
KGrRuleBook::Timing::ewalk
int ewalk
Definition: kgrrulebook.h:70
KGrRuleBook::findBestWay
virtual Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)=0
KGrTraditionalRules::~KGrTraditionalRules
~KGrTraditionalRules()
Definition: kgrrulebook.cpp:80
KGrScavengerRules
Definition: kgrrulebook.h:137
KGrKGoldrunnerRules
Definition: kgrrulebook.h:117
KGrTraditionalRules
Definition: kgrrulebook.h:92
KGrKGoldrunnerRules::~KGrKGoldrunnerRules
~KGrKGoldrunnerRules()
Definition: kgrrulebook.cpp:474
KGrRuleBook::turnAnywhere
bool turnAnywhere() const
Definition: kgrrulebook.h:43
KGrRuleBook::mEnemiesShowGold
bool mEnemiesShowGold
Enemies show when they are carrying gold.
Definition: kgrrulebook.h:85
KGrRuleBook::Timing
Definition: kgrrulebook.h:67
kgrglobals.h
KGrRuleBook::getEnemyTimes
char getEnemyTimes(int &runTime, int &fallTime, int &trapTime)
Definition: kgrrulebook.h:53
KGrRuleBook::setTiming
void setTiming(const int enemyCount=0)
Definition: kgrrulebook.cpp:40
KGrTraditionalRules::KGrTraditionalRules
KGrTraditionalRules(QObject *parent)
Definition: kgrrulebook.cpp:61
KGrRuleBook::grid
KGrLevelGrid * grid
Definition: kgrrulebook.h:88
KGrRuleBook::enemiesShowGold
bool enemiesShowGold() const
Definition: kgrrulebook.h:44
KGrRuleBook::Timing::hwalk
int hwalk
Definition: kgrrulebook.h:68
KGrScavengerRules::findBestWay
Direction findBestWay(const int eI, const int eJ, const int hI, const int hJ, KGrLevelGrid *pGrid, bool leftRightSearch=true)
Definition: kgrrulebook.cpp:678
KGrRuleBook::mVariableTiming
bool mVariableTiming
More enemies imply less speed.
Definition: kgrrulebook.h:78
QObject::parent
QObject * parent() const
KGrRuleBook::pointsPerCell
int pointsPerCell() const
Definition: kgrrulebook.h:42
KGrRuleBook::mTurnAnywhere
bool mTurnAnywhere
Can change direction anywhere in grid-cell.
Definition: kgrrulebook.h:84
KGrRuleBook::Timing::ecaptive
int ecaptive
Definition: kgrrulebook.h:72
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