31 #include <kgameclock.h>
32 #include <kmahjonggtileset.h>
33 #include <kmahjonggbackground.h>
36 #include <krandomsequence.h>
42 #include <phonon/mediaobject.h>
45 static int sizeX[6] = {14, 16, 18, 24, 26, 30};
46 static int sizeY[6] = { 6, 9, 8, 12, 14, 16};
82 kDebug() <<
"PossibleMove";
85 kDebug() <<
" Path:" << iter->x <<
"," << iter->y;
89 kDebug() <<
" hasSlide";
91 kDebug() <<
" Slide:" << iter->x <<
"," << iter->y;
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) { }
171 void dumpBoard()
const;
172 void dumpBoard(
const int *)
const;
181 bool solvable(
bool noRestore =
false);
262 void undrawConnection();
268 bool gravity(
int column,
bool update);
284 int lineWidth()
const;
286 void setField(
int x,
int y,
int value);
287 int field(
int x,
int y)
const;
288 void updateField(
int,
int);
291 void clearHighlight();
296 bool tilesMatch(
int tile1,
int tile2)
const;
304 bool canMakePath(
int x1,
int y1,
int x2,
int y2)
const;
313 bool canSlideTiles(
int x1,
int y1,
int x2,
int y2,
Path &path)
const;
323 int findPath(
int x1,
int y1,
int x2,
int y2,
PossibleMoves &possibleMoves)
const;
333 int findSimplePath(
int x1,
int y1,
int x2,
int y2,
PossibleMoves &possibleMoves)
const;
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;
342 void marked(
int x,
int y);
343 void madeMove(
int x1,
int y1,
int x2,
int y2,
Path slide =
Path());
348 void gravity(
bool update);
351 KGameClock m_gameClock;
353 KMahjonggTileset m_tiles;
354 KMahjonggBackground m_background;
356 KRandomSequence m_random;
372 enum GameState { Normal, Paused, Stuck, Over };
373 GameState m_gameState;
378 bool m_chineseStyleFlag;
379 bool m_tilesCanSlideFlag;
382 int m_highlightedTile;
384 bool m_paintConnection;
385 bool m_paintPossibleMoves;
386 bool m_paintInProgress;
Path m_slide
path representing the movement of the last sliding tile
bool canUndo() const
Returns if undo step is available.
bool m_hasSlide
flag set if the move requires a slide
void setGameStuckEnabled(bool enabled)
Sets whether there are no matching tiles left.
bool loadTileset(const QString &)
Loads the given tileset.
bool hasCheated() const
Returns whether player is in cheat mode.
void loadSettings()
Loads the game settings.
bool isOver() const
Returns whether the game is over.
int m_tile1
type of tile at first set of coordinates
bool isInPath(int x, int y) const
bool solvableFlag() const
void setChineseStyleFlag(bool b)
int tilesLeft() const
Returns the number of tiles left on the board.
bool solvable(bool noRestore=false)
Returns whether the current game is solvable.
virtual QSize sizeHint() const
bool isPaused() const
Returns whether the game is in pause mode.
int m_y2
coordinates of the two tiles that matched
int m_slideY1
original y coordinate of the last slided tile
int m_slideX2
final x coordinate of the last slided tile
Path m_path
path used to connect the two tiles
void setSize(int x, int y)
void setTilesCanSlideFlag(bool b)
Class holding the game board and its functions.
void resetUndo()
Resets the undo history.
bool isStuck() const
Returns whether there are still matching tiles left.
virtual void resizeEvent(QResizeEvent *e)
Class holding a move on the board made by the player.
virtual void paintEvent(QPaintEvent *e)
Move(int x1, int y1, int x2, int y2, int tile)
Class holding a possible move and its functions.
QList< PossibleMove > PossibleMoves
A list of possible moves the player has to choose between.
int m_tile2
type of tile at second set of coordinates
void cheatStatusChanged()
bool loadBackground(const QString &)
Loads the given background.
void setSoundsEnabled(bool enabled)
Enables / disables sounds.
PossibleMove(Path &path, Path &slide)
void newGame()
Does most of the newGame work.
void setSolvableFlag(bool b)
int currentTime() const
Returns the current game time in seconds.
void resetRedo()
Resets the redo history.
Struct holding a position on the board (x,y)
QList< Position > Path
A list of positions (at least 2) makes a Path.
int m_slideX1
original x coordinate of the last slided tile
void setGravityFlag(bool b)
void setPauseEnabled(bool enabled)
Controls the pause mode.
bool canRedo() const
Returns if redo step is available.
const_iterator constEnd() const
void redo()
Redoes one step.
const_iterator constBegin() const
void resetTimer()
Resets the game timer.
virtual void mousePressEvent(QMouseEvent *e)
void setGameOverEnabled(bool enabled)
Sets whether the game is over.
Move(int x1, int y1, int x2, int y2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2)
bool m_hasSlide
if we performed a slide during the move
void undo()
Undoes one step.
void selectAMatchingTile()
int m_slideY2
final y coordinate of the last slided tile
void setCheatModeEnabled(bool enabled)
Sets whether the game is in cheat mode.
bool hint_I(PossibleMoves &possibleMoves) const
Move(int x1, int y1, int x2, int y2, int tile1, int tile2)