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

kmahjongg

  • sources
  • kde-4.14
  • kdegames
  • kmahjongg
GameData.h
Go to the documentation of this file.
1 /* kmahjongg, the classic mahjongg game for KDE project
2  *
3  * Copyright (C) 1997 Mathias Mueller <in5y158@public.uni-hamburg.de>
4  * Copyright (C) 2006-2007 Mauricio Piacentini <mauricio@tabuleiro.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 
20 #ifndef GAMEDATA_H
21 #define GAMEDATA_H
22 
23 
24 #include "KmTypes.h"
25 #include "BoardLayout.h"
26 
27 #include <QByteArray>
28 #include <QVector>
29 
30 #include <krandomsequence.h>
31 
32 
33 // tiles symbol names:
34 /*#define TILE_OFFSET 2
35 
36 #define TILE_CHARACTER ( 0 + TILE_OFFSET)
37 #define TILE_BAMBOO ( 9 + TILE_OFFSET)
38 #define TILE_ROD (18 + TILE_OFFSET)
39 #define TILE_SEASON (27 + TILE_OFFSET)
40 #define TILE_WIND (31 + TILE_OFFSET)
41 #define TILE_DRAGON (36 + TILE_OFFSET)
42 #define TILE_FLOWER (39 + TILE_OFFSET)*/
43 
44 
51 class GameData
52 {
53 public:
59  explicit GameData(BoardLayout *boardlayout);
60 
63  ~GameData();
64 
72  void putTile(short e, short y, short x, UCHAR f);
73 
79  void putTile(POSITION &pos) {putTile(pos.e, pos.y, pos.x, pos.f);}
80 
89  bool tilePresent(int z, int y, int x);
90 
99  bool partTile(int z, int y, int x);
100 
108  UCHAR BoardData(short z, short y, short x);
109 
117  void setBoardData(short z, short y, short x, UCHAR value);
118 
126  UCHAR MaskData(short z, short y, short x);
127 
135  UCHAR HighlightData(short z, short y, short x);
136 
144  void setHighlightData(short z, short y, short x, UCHAR value);
145 
152  POSITION& MoveListData(short i);
153 
160  void setMoveListData(short i, POSITION &value);
161 
166  char* getMaskBytes() {return Mask.data();}
167 
168  bool saveToStream(QDataStream &out);
169  bool loadFromStream(QDataStream &in);
170 
171  void generatePositionDepends();
172  void generateTilePositions();
173 
174  bool generateStartPosition2();
175 
176  bool findMove(POSITION &posA, POSITION &posB);
177  int moveCount();
178  short findAllMatchingTiles(POSITION &posA);
179  void initialiseRemovedTiles();
180  void setRemovedTilePair(POSITION &a, POSITION &b);
181  void clearRemovedTilePair(POSITION &a, POSITION &b);
182  bool isMatchingTile(POSITION &Pos1, POSITION &Pos2);
183  void shuffle();
184  POSITION& getFromPosTable(int index) {return PosTable[index];}
185 
186  int allow_undo;
187  int allow_redo;
188 
189  USHORT TileNum;
190  USHORT MaxTileNum;
191 
192  //Board Layout dimensions
193  short m_width;
194  short m_height;
195  short m_depth;
196  short m_maxTiles;
197 
198  KRandomSequence random;
199 
200 private:
201  int tileAt(int x, int y, int z);
202  bool generateSolvableGame();
203  bool onlyFreeInLine(int position);
204  int selectPosition(int lastPosition);
205  void placeTile(int position, int tile);
206  void updateDepend(int position);
207 
208  //other generation bits
209  void randomiseFaces();
210  void getFaces(POSITION &a, POSITION &b);
211 
212  int tilesAllocated;
213  int tilesUsed;
214 
215  UCHAR tilePair[144];
216 
217  // storage to keep track of removed tiles
218  unsigned char removedCharacter[9];
219  unsigned char removedBamboo[9];
220  unsigned char removedRod[9];
221  unsigned char removedDragon[3];
222  unsigned char removedWind[9];
223  unsigned char removedFlower[4];
224  unsigned char removedSeason[4];
225 
226  // new bits for new game generation, with solvability. Scratch storage
227  int numTilesToGenerate;
228 
229  QByteArray Board;
230  QByteArray Mask;
231  QByteArray Highlight;
232  QVector<POSITION> MoveList;
233 
234  QVector<POSITION> tilePositions;
235  QVector<DEPENDENCY> positionDepends;
236 
237  //PosTable, scratch storage used for highlighting matching tiles
238  QVector<POSITION> PosTable;
239 };
240 
241 
242 #endif // GAMEDATA_H
GameData::putTile
void putTile(short e, short y, short x, UCHAR f)
Method Description.
Definition: GameData.cpp:51
GameData::generateTilePositions
void generateTilePositions()
Definition: GameData.cpp:143
GameData::getFromPosTable
POSITION & getFromPosTable(int index)
Definition: GameData.h:184
GameData::m_height
short m_height
Definition: GameData.h:194
QByteArray
GameData::generatePositionDepends
void generatePositionDepends()
Definition: GameData.cpp:165
QDataStream
GameData::initialiseRemovedTiles
void initialiseRemovedTiles()
Definition: GameData.cpp:871
pos::e
USHORT e
Member Description.
Definition: KmTypes.h:36
GameData::m_depth
short m_depth
Definition: GameData.h:195
KmTypes.h
GameData::getMaskBytes
char * getMaskBytes()
Method Description.
Definition: GameData.h:166
GameData::GameData
GameData(BoardLayout *boardlayout)
Constructor.
Definition: GameData.cpp:25
GameData::clearRemovedTilePair
void clearRemovedTilePair(POSITION &a, POSITION &b)
Definition: GameData.cpp:824
GameData::setMoveListData
void setMoveListData(short i, POSITION &value)
Method Description.
Definition: GameData.cpp:134
GameData::MoveListData
POSITION & MoveListData(short i)
Method Description.
Definition: GameData.cpp:124
GameData::~GameData
~GameData()
Default Destructor.
Definition: GameData.cpp:47
GameData::generateStartPosition2
bool generateStartPosition2()
Definition: GameData.cpp:549
pos::x
USHORT x
Member Description.
Definition: KmTypes.h:38
GameData::MaskData
UCHAR MaskData(short z, short y, short x)
Method Description.
Definition: GameData.cpp:74
GameData::BoardData
UCHAR BoardData(short z, short y, short x)
Method Description.
Definition: GameData.cpp:104
GameData::allow_redo
int allow_redo
Definition: GameData.h:187
GameData::saveToStream
bool saveToStream(QDataStream &out)
Definition: GameData.cpp:1073
GameData::m_maxTiles
short m_maxTiles
Definition: GameData.h:196
GameData::MaxTileNum
USHORT MaxTileNum
Definition: GameData.h:190
BoardLayout.h
GameData::loadFromStream
bool loadFromStream(QDataStream &in)
Definition: GameData.cpp:1047
pos::y
USHORT y
Member Description.
Definition: KmTypes.h:37
GameData::TileNum
USHORT TileNum
Definition: GameData.h:189
GameData::moveCount
int moveCount()
Definition: GameData.cpp:951
pos
struct pos POSITION
Definition: KmTypes.h:34
GameData::findAllMatchingTiles
short findAllMatchingTiles(POSITION &posA)
Definition: GameData.cpp:1005
GameData::tilePresent
bool tilePresent(int z, int y, int x)
Method Description.
Definition: GameData.cpp:59
GameData::isMatchingTile
bool isMatchingTile(POSITION &Pos1, POSITION &Pos2)
Definition: GameData.cpp:762
USHORT
unsigned short USHORT
Definition: KmTypes.h:27
QVector
GameData::shuffle
void shuffle()
Definition: GameData.cpp:1098
GameData::random
KRandomSequence random
Definition: GameData.h:198
GameData::setBoardData
void setBoardData(short z, short y, short x, UCHAR value)
Method Description.
Definition: GameData.cpp:114
GameData::findMove
bool findMove(POSITION &posA, POSITION &posB)
Definition: GameData.cpp:884
QByteArray::data
char * data()
BoardLayout
This class implements methods for loading and manipulating board.
Definition: BoardLayout.h:36
GameData::putTile
void putTile(POSITION &pos)
Method Description.
Definition: GameData.h:79
UCHAR
unsigned char UCHAR
Definition: KmTypes.h:25
GameData::HighlightData
UCHAR HighlightData(short z, short y, short x)
Method Description.
Definition: GameData.cpp:84
GameData::setHighlightData
void setHighlightData(short z, short y, short x, UCHAR value)
Method Description.
Definition: GameData.cpp:94
GameData
This class implements.
Definition: GameData.h:51
GameData::partTile
bool partTile(int z, int y, int x)
Method Description.
Definition: GameData.cpp:69
GameData::allow_undo
int allow_undo
Definition: GameData.h:186
GameData::m_width
short m_width
Definition: GameData.h:193
pos::f
USHORT f
Member Description.
Definition: KmTypes.h:39
GameData::setRemovedTilePair
void setRemovedTilePair(POSITION &a, POSITION &b)
Definition: GameData.cpp:777
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmahjongg

Skip menu "kmahjongg"
  • 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