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

KShisen

  • sources
  • kde-4.14
  • kdegames
  • kshisen
  • src
board.h
Go to the documentation of this file.
1 /***************************************************************************
2  * KShisen - A japanese game similar to mahjongg *
3  * Copyright 1997 Mario Weilguni <mweilguni@sime.com> *
4  * Copyright 2002-2004 Dave Corrie <kde@davecorrie.com> *
5  * Copyright 2007 Mauricio Piacentini <mauricio@tabuleiro.com> *
6  * Copyright 2009-2012 Frederik Schwarzer <schwarzer@kde.org> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
20  ***************************************************************************/
21 
22 // KMahjonggLib integration and SVG support for KDE 4: Mauricio Piacentini <mauricio@tabuleiro.com>
23 
24 #ifndef BOARD_H
25 #define BOARD_H
26 
27 #include "debug.h"
28 
29 #include <KgSound>
30 
31 #include <kgameclock.h>
32 #include <kmahjonggtileset.h>
33 #include <kmahjonggbackground.h>
34 
35 #include <kdebug.h>
36 #include <krandomsequence.h>
37 
38 #include <QList>
39 #include <QSize>
40 #include <QWidget>
41 
42 #include <phonon/mediaobject.h>
43 
44 // used in board.cpp and app.cpp, thus defined here
45 static int sizeX[6] = {14, 16, 18, 24, 26, 30};
46 static int sizeY[6] = { 6, 9, 8, 12, 14, 16};
47 
51 struct Position {
52  Position() : x(0), y(0) { }
53  Position(int _x, int _y) : x(_x), y(_y) { }
54  int x;
55  int y;
56 };
57 
61 typedef QList<Position> Path;
62 
71 class PossibleMove
72 {
73 public:
74  PossibleMove(Path &path) :
75  m_path(path), m_hasSlide(false) { }
76  PossibleMove(Path &path, Path &slide) :
77  m_path(path), m_hasSlide(true), m_slide(slide) { }
78 
79  bool isInPath(int x, int y) const;
80 
81  void Debug() const {
82  kDebug() << "PossibleMove";
83  QList<Position>::const_iterator iter;
84  for (iter = m_path.constBegin(); iter != m_path.constEnd(); ++iter) {
85  kDebug() << " Path:" << iter->x << "," << iter->y;
86  }
87 
88  if (m_hasSlide) {
89  kDebug() << " hasSlide";
90  for (iter = m_slide.constBegin(); iter != m_slide.constEnd(); ++iter) {
91  kDebug() << " Slide:" << iter->x << "," << iter->y;
92  }
93  }
94  }
95 
96  Path m_path;
97  bool m_hasSlide;
98  Path m_slide;
99 };
100 
104 typedef QList<PossibleMove> PossibleMoves;
105 
106 
112 class Move
113 {
114 public:
115  Move(int x1, int y1, int x2, int y2, int tile) :
116  m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2), m_tile1(tile), m_tile2(tile), m_hasSlide(false), m_slideX1(-1), m_slideY1(-1), m_slideX2(-1), m_slideY2(-1) { }
117  Move(int x1, int y1, int x2, int y2, int tile1, int tile2) :
118  m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2), m_tile1(tile1), m_tile2(tile2), m_hasSlide(false), m_slideX1(-1), m_slideY1(-1), m_slideX2(-1), m_slideY2(-1) { }
119  Move(int x1, int y1, int x2, int y2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2) :
120  m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2), m_tile1(tile1), m_tile2(tile2), m_hasSlide(true), m_slideX1(slideX1), m_slideY1(slideY1), m_slideX2(slideX2), m_slideY2(slideY2) { }
121 
122  int m_x1, m_y1, m_x2, m_y2;
123  int m_tile1;
124  int m_tile2;
125  bool m_hasSlide;
126  int m_slideX1;
127  int m_slideY1;
128  int m_slideX2;
129  int m_slideY2;
130 };
131 
132 
136 class Board : public QWidget
137 {
138  Q_OBJECT
139 
140 public:
141  Board(QWidget *parent = 0);
142  ~Board();
143 
144  static const int nTiles = 42;
145 
146  virtual void paintEvent(QPaintEvent *e);
147  virtual void mousePressEvent(QMouseEvent *e);
148  virtual void resizeEvent(QResizeEvent *e);
149 
150  void setDelay(int);
151  int delay() const;
152 
154  bool canUndo() const;
156  bool canRedo() const;
158  void undo();
160  void redo();
161 
162  void setSize(int x, int y);
163  void resizeBoard();
164 
165  void showHint();
166  bool hint_I(PossibleMoves &possibleMoves) const;
167 
168 #ifdef DEBUGGING
169  void makeHintMove();
170  void finish();
171  void dumpBoard() const;
172  void dumpBoard(const int *) const;
173 #endif
174 
176  int tilesLeft() const;
178  int currentTime() const;
179 
181  bool solvable(bool noRestore = false); // const?
182 
183  bool solvableFlag() const;
184  void setSolvableFlag(bool b);
185  bool gravityFlag() const;
186  void setGravityFlag(bool b);
187  void setChineseStyleFlag(bool b);
188  void setTilesCanSlideFlag(bool b);
189 
190  int xTiles() const;
191  int yTiles() const;
192 
194  void resetTimer();
196  void resetUndo();
198  void resetRedo();
200  void setGameStuckEnabled(bool enabled);
202  void setGameOverEnabled(bool enabled);
204  void setCheatModeEnabled(bool enabled);
205 
209  bool isOver() const;
210 
214  bool isPaused() const;
215 
219  bool isStuck() const;
220 
224  bool hasCheated() const;
225 
226 signals:
227  void markMatched(); // unused?
228  void newGameStarted();
229  void changed();
230  void endOfGame();
231  void resized();
232  void invalidMove();
233  void tilesDoNotMatch();
234  void selectATile();
235  void selectAMove();
236  void selectAMatchingTile();
237  void cheatStatusChanged();
238 
239 public slots:
245  void newGame();
246 
248  void setPauseEnabled(bool enabled);
249 
253  void setSoundsEnabled(bool enabled);
255  void loadSettings();
257  bool loadTileset(const QString &);
259  bool loadBackground(const QString &);
260 
261 private slots:
262  void undrawConnection();
263 
268  bool gravity(int column, bool update);
269 
270 protected:
271  virtual QSize sizeHint() const;
272 
273 private: // functions
278  int xOffset() const;
279  int yOffset() const;
280 
284  int lineWidth() const;
285 
286  void setField(int x, int y, int value);
287  int field(int x, int y) const;
288  void updateField(int, int);
289  void showInfoRect(QPainter &, const QString &message);
290  void drawTiles(QPainter &, QPaintEvent *);
291  void clearHighlight();
292 
296  bool tilesMatch(int tile1, int tile2) const;
297 
304  bool canMakePath(int x1, int y1, int x2, int y2) const;
305 
313  bool canSlideTiles(int x1, int y1, int x2, int y2, Path &path) const;
314 
323  int findPath(int x1, int y1, int x2, int y2, PossibleMoves &possibleMoves) const;
324 
333  int findSimplePath(int x1, int y1, int x2, int y2, PossibleMoves &possibleMoves) const;
334  void performMove(PossibleMove &possibleMoves);
335  void performSlide(int x, int y, Path& s);
336  void reverseSlide(int x, int y, int slideX1, int slideY1, int slideX2, int slideY2);
337  bool isTileHighlighted(int x, int y) const;
338  void drawConnection();
339  void drawPossibleMoves(bool b);
340  QPoint midCoord(int x, int y) const;
341  void unmarkTile();
342  void marked(int x, int y);
343  void madeMove(int x1, int y1, int x2, int y2, Path slide = Path());
344 
348  void gravity(bool update);
349 
350 private:
351  KGameClock m_gameClock;
352 
353  KMahjonggTileset m_tiles;
354  KMahjonggBackground m_background;
355 
356  KRandomSequence m_random;
357 
358  QList<Move*> m_undo;
359  QList<Move*> m_redo;
360 
361  int m_markX;
362  int m_markY;
363  Path m_connection;
364  PossibleMoves m_possibleMoves;
365  int *m_field;
366  int m_xTiles;
367  int m_yTiles;
368  int m_delay;
369  int m_level;
370  int m_shuffle;
371 
372  enum GameState { Normal, Paused, Stuck, Over };
373  GameState m_gameState;
374  bool m_cheat;
375 
376  bool m_gravityFlag;
377  bool m_solvableFlag;
378  bool m_chineseStyleFlag;
379  bool m_tilesCanSlideFlag;
380  QList<int> m_gravCols;
381 
382  int m_highlightedTile;
383 
384  bool m_paintConnection;
385  bool m_paintPossibleMoves;
386  bool m_paintInProgress;
387  QPair<int, int> m_tileRemove1;
388  QPair<int, int> m_tileRemove2;
389  KgSound m_soundPick;
390  KgSound m_soundFall;
391 };
392 
393 #endif // BOARD_H
394 
395 // vim: expandtab:tabstop=4:shiftwidth=4
396 // kate: space-indent on; indent-width 4
PossibleMove::m_slide
Path m_slide
path representing the movement of the last sliding tile
Definition: board.h:98
Board::canUndo
bool canUndo() const
Returns if undo step is available.
Definition: board.cpp:1454
QResizeEvent
QWidget
Board::yTiles
int yTiles() const
Definition: board.cpp:184
Position::Position
Position()
Definition: board.h:52
PossibleMove::m_hasSlide
bool m_hasSlide
flag set if the move requires a slide
Definition: board.h:97
debug.h
Board::tilesDoNotMatch
void tilesDoNotMatch()
Board::setGameStuckEnabled
void setGameStuckEnabled(bool enabled)
Sets whether there are no matching tiles left.
Definition: board.cpp:1962
Board::loadTileset
bool loadTileset(const QString &)
Loads the given tileset.
Definition: board.cpp:137
Position::y
int y
y position
Definition: board.h:55
Board::hasCheated
bool hasCheated() const
Returns whether player is in cheat mode.
Definition: board.cpp:2012
Board::loadSettings
void loadSettings()
Loads the game settings.
Definition: board.cpp:99
Board::isOver
bool isOver() const
Returns whether the game is over.
Definition: board.cpp:1997
Move::m_tile1
int m_tile1
type of tile at first set of coordinates
Definition: board.h:123
QWidget::y
int y() const
PossibleMove::isInPath
bool isInPath(int x, int y) const
Definition: board.cpp:43
Board::solvableFlag
bool solvableFlag() const
Definition: board.cpp:1858
Board::setChineseStyleFlag
void setChineseStyleFlag(bool b)
Definition: board.cpp:1892
QPoint
Board::tilesLeft
int tilesLeft() const
Returns the number of tiles left on the board.
Definition: board.cpp:1809
QMouseEvent
Board::showHint
void showHint()
Definition: board.cpp:1709
Board::nTiles
static const int nTiles
Definition: board.h:144
Board::solvable
bool solvable(bool noRestore=false)
Returns whether the current game is solvable.
Definition: board.cpp:1829
Board::resizeBoard
void resizeBoard()
Definition: board.cpp:422
QWidget::update
void update()
Board::sizeHint
virtual QSize sizeHint() const
Definition: board.cpp:1930
Board::isPaused
bool isPaused() const
Returns whether the game is in pause mode.
Definition: board.cpp:2002
Board::gravityFlag
bool gravityFlag() const
Definition: board.cpp:1875
Move::m_y2
int m_y2
coordinates of the two tiles that matched
Definition: board.h:122
Board::Board
Board(QWidget *parent=0)
Definition: board.cpp:69
Move::m_slideY1
int m_slideY1
original y coordinate of the last slided tile
Definition: board.h:127
Move::m_slideX2
int m_slideX2
final x coordinate of the last slided tile
Definition: board.h:128
PossibleMove::m_path
Path m_path
path used to connect the two tiles
Definition: board.h:96
Position::Position
Position(int _x, int _y)
Definition: board.h:53
QWidget::enabled
enabled
Board::setSize
void setSize(int x, int y)
Definition: board.cpp:381
Board::setTilesCanSlideFlag
void setTilesCanSlideFlag(bool b)
Definition: board.cpp:1902
Board
Class holding the game board and its functions.
Definition: board.h:136
Move::m_y1
int m_y1
Definition: board.h:122
Board::resetUndo
void resetUndo()
Resets the undo history.
Definition: board.cpp:1944
QWidget::x
int x() const
Board::isStuck
bool isStuck() const
Returns whether there are still matching tiles left.
Definition: board.cpp:2007
Board::resizeEvent
virtual void resizeEvent(QResizeEvent *e)
Definition: board.cpp:412
QPainter
Board::delay
int delay() const
Definition: board.cpp:1433
Move
Class holding a move on the board made by the player.
Definition: board.h:112
Board::paintEvent
virtual void paintEvent(QPaintEvent *e)
Definition: board.cpp:679
Move::Move
Move(int x1, int y1, int x2, int y2, int tile)
Definition: board.h:115
PossibleMove
Class holding a possible move and its functions.
Definition: board.h:71
sizeX
static int sizeX[6]
Definition: board.h:45
PossibleMoves
QList< PossibleMove > PossibleMoves
A list of possible moves the player has to choose between.
Definition: board.h:104
Board::selectATile
void selectATile()
Move::m_tile2
int m_tile2
type of tile at second set of coordinates
Definition: board.h:124
Board::cheatStatusChanged
void cheatStatusChanged()
QString
QList< Position >
Board::loadBackground
bool loadBackground(const QString &)
Loads the given background.
Definition: board.cpp:158
Board::setSoundsEnabled
void setSoundsEnabled(bool enabled)
Enables / disables sounds.
Definition: board.cpp:2017
PossibleMove::PossibleMove
PossibleMove(Path &path, Path &slide)
Definition: board.h:76
Board::invalidMove
void invalidMove()
QPair< int, int >
PossibleMove::Debug
void Debug() const
Definition: board.h:81
Board::endOfGame
void endOfGame()
QSize
Board::changed
void changed()
Board::selectAMove
void selectAMove()
Board::~Board
~Board()
Definition: board.cpp:94
Board::xTiles
int xTiles() const
Definition: board.cpp:179
Board::newGame
void newGame()
Does most of the newGame work.
Definition: board.cpp:436
Position::x
int x
x position
Definition: board.h:54
Board::setSolvableFlag
void setSolvableFlag(bool b)
Definition: board.cpp:1863
PossibleMove::PossibleMove
PossibleMove(Path &path)
Definition: board.h:74
Board::newGameStarted
void newGameStarted()
Board::currentTime
int currentTime() const
Returns the current game time in seconds.
Definition: board.cpp:1824
Board::resized
void resized()
Board::resetRedo
void resetRedo()
Resets the redo history.
Definition: board.cpp:1953
Position
Struct holding a position on the board (x,y)
Definition: board.h:51
Path
QList< Position > Path
A list of positions (at least 2) makes a Path.
Definition: board.h:61
Move::m_slideX1
int m_slideX1
original x coordinate of the last slided tile
Definition: board.h:126
Board::setGravityFlag
void setGravityFlag(bool b)
Definition: board.cpp:1880
Board::setPauseEnabled
void setPauseEnabled(bool enabled)
Controls the pause mode.
Definition: board.cpp:1914
QPaintEvent
Board::canRedo
bool canRedo() const
Returns if redo step is available.
Definition: board.cpp:1459
sizeY
static int sizeY[6]
Definition: board.h:46
QList::constEnd
const_iterator constEnd() const
Board::redo
void redo()
Redoes one step.
Definition: board.cpp:1686
QList::constBegin
const_iterator constBegin() const
Board::resetTimer
void resetTimer()
Resets the game timer.
Definition: board.cpp:1939
Board::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e)
Definition: board.cpp:281
Board::setDelay
void setDelay(int)
Definition: board.cpp:1425
Board::setGameOverEnabled
void setGameOverEnabled(bool enabled)
Sets whether the game is over.
Definition: board.cpp:1978
Move::Move
Move(int x1, int y1, int x2, int y2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2)
Definition: board.h:119
QObject::parent
QObject * parent() const
Move::m_hasSlide
bool m_hasSlide
if we performed a slide during the move
Definition: board.h:125
Board::undo
void undo()
Undoes one step.
Definition: board.cpp:1464
Move::m_x2
int m_x2
Definition: board.h:122
Board::selectAMatchingTile
void selectAMatchingTile()
Move::m_slideY2
int m_slideY2
final y coordinate of the last slided tile
Definition: board.h:129
Board::setCheatModeEnabled
void setCheatModeEnabled(bool enabled)
Sets whether the game is in cheat mode.
Definition: board.cpp:1988
Board::hint_I
bool hint_I(PossibleMoves &possibleMoves) const
Definition: board.cpp:1779
Move::Move
Move(int x1, int y1, int x2, int y2, int tile1, int tile2)
Definition: board.h:117
Board::markMatched
void markMatched()
Move::m_x1
int m_x1
Definition: board.h:122
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KShisen

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