Commit e3707da1 authored by Frederik Schwarzer's avatar Frederik Schwarzer

Swap out classes to separate files.

parent 0e62d28d
......@@ -6,9 +6,9 @@ set(KF5_MIN_VERSION "5.15.0")
find_package(ECM 1.7.0 REQUIRED NO_MODULE)
#if(ENABLE_CLAZY)
# set(CMAKE_CXX_COMPILER clazy)
#endif()
if(ENABLE_CLAZY)
set(CMAKE_CXX_COMPILER clazy)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
......
......@@ -2,6 +2,8 @@ set(kshisen_SRCS
app.cpp
board.cpp
main.cpp
move.cpp
possiblemove.cpp
)
ki18n_wrap_ui(kshisen_SRCS settings.ui)
......@@ -25,4 +27,3 @@ install(TARGETS kshisen ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES kshisen.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kshisenui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kshisen)
......@@ -3,7 +3,7 @@
* Copyright 1997 Mario Weilguni <mweilguni@sime.com> *
* Copyright 2002-2004 Dave Corrie <kde@davecorrie.com> *
* Copyright 2007 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Copyright 2009-2011 Frederik Schwarzer <schwarzer@kde.org> *
* Copyright 2009-2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......
......@@ -2,7 +2,7 @@
* KShisen - A japanese game similar to mahjongg *
* Copyright 1997 Mario Weilguni <mweilguni@sime.com> *
* Copyright 2002-2004 Dave Corrie <kde@davecorrie.com> *
* Copyright 2009,2010 Frederik Schwarzer <schwarzer@kde.org> *
* Copyright 2009,2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
* Copyright 1997 Mario Weilguni <mweilguni@sime.com> *
* Copyright 2002-2004 Dave Corrie <kde@davecorrie.com> *
* Copyright 2007 Mauricio Piacentini <mauricio@tabuleiro.com> *
* Copyright 2009-2012 Frederik Schwarzer <schwarzer@kde.org> *
* Copyright 2009-2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -39,136 +39,20 @@
#include <KGameClock>
#include <KgSound>
// KMahjongg
// LibKMahjongg
#include <kmahjonggbackground.h>
#include <kmahjonggtileset.h>
// KShisen
#include "debug.h"
using TilePos = QPoint;
/**
* A list of positions (at least 2) makes a Path
*/
using Path = QList<TilePos>;
/**
* @brief Class holding a possible move and its functions
*
* A PossibleMove is a connection Path between two tiles
* and optionally a slide Path.
* Sometimes for a couple of tiles to match there may be multiple
* possible moves for the player to choose between.
*/
class PossibleMove
{
public:
explicit PossibleMove(Path & path)
: m_path(path)
, m_hasSlide(false)
, m_slide()
{
}
PossibleMove(Path & path, Path & slide)
: m_path(path)
, m_hasSlide(true)
, m_slide(slide)
{
}
bool isInPath(TilePos const & tilePos) const;
void Debug() const
{
qCDebug(KSHISEN_LOG) << "PossibleMove";
foreach (auto iter, m_path) {
qCDebug(KSHISEN_LOG) << " Path:" << iter.x() << "," << iter.y();
}
if (m_hasSlide) {
qCDebug(KSHISEN_LOG) << " hasSlide";
foreach (auto iter, m_slide) {
qCDebug(KSHISEN_LOG) << " Slide:" << iter.x() << "," << iter.y();
}
}
}
Path m_path; ///< path used to connect the two tiles
bool m_hasSlide; ///< flag set if the move requires a slide
Path m_slide; ///< path representing the movement of the last sliding tile
};
#include "move.h"
#include "possiblemove.h"
/**
* A list of possible moves the player has to choose between
*/
using PossibleMoves = QList<PossibleMove>;
/**
* @brief Class holding a move on the board made by the player
*
* Contains all the information needed to undo or redo a move.
*/
class Move
{
public:
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile)
, m_tile2(tile)
, m_hasSlide(false)
, m_slideX1(-1)
, m_slideY1(-1)
, m_slideX2(-1)
, m_slideY2(-1)
{
}
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile1)
, m_tile2(tile2)
, m_hasSlide(false)
, m_slideX1(-1)
, m_slideY1(-1)
, m_slideX2(-1)
, m_slideY2(-1)
{
}
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile1)
, m_tile2(tile2)
, m_hasSlide(true)
, m_slideX1(slideX1)
, m_slideY1(slideY1)
, m_slideX2(slideX2)
, m_slideY2(slideY2)
{
}
int m_x1, m_y1, m_x2, m_y2; ///< coordinates of the two tiles that matched
int m_tile1; ///< type of tile at first set of coordinates
int m_tile2; ///< type of tile at second set of coordinates
bool m_hasSlide; ///< if we performed a slide during the move
int m_slideX1; ///< original x coordinate of the last slided tile
int m_slideY1; ///< original y coordinate of the last slided tile
int m_slideX2; ///< final x coordinate of the last slided tile
int m_slideY2; ///< final y coordinate of the last slided tile
};
/**
* @brief Class holding the game board and its functions.
*/
......@@ -368,7 +252,7 @@ private: // functions
*/
int findSimplePath(TilePos const & tilePos1, TilePos const & tilePos2, PossibleMoves & possibleMoves) const;
void performMove(PossibleMove & possibleMoves);
void performSlide(TilePos const & tilePos, Path & slide);
void performSlide(TilePos const & tilePos, Path const & slide);
void reverseSlide(TilePos const & tilePos, int slideX1, int slideY1, int slideX2, int slideY2);
bool isTileHighlighted(TilePos const & tilePos) const;
void drawConnection();
......
......@@ -2,7 +2,7 @@
* KShisen - A japanese game similar to mahjongg *
* Copyright 1997 Mario Weilguni <mweilguni@sime.com> *
* Copyright 2002-2004 Dave Corrie <kde@davecorrie.com> *
* Copyright 2009,2010 Frederik Schwarzer <schwarzer@kde.org> *
* Copyright 2009,2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......
/***************************************************************************
* KShisen - A japanese game similar to mahjongg *
* Copyright 2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
// own
#include "move.h"
Move::Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile)
, m_tile2(tile)
, m_hasSlide(false)
, m_slideX1(-1)
, m_slideY1(-1)
, m_slideX2(-1)
, m_slideY2(-1)
{
}
Move::Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile1)
, m_tile2(tile2)
, m_hasSlide(false)
, m_slideX1(-1)
, m_slideY1(-1)
, m_slideX2(-1)
, m_slideY2(-1)
{
}
Move::Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2)
: m_x1(tilePos1.x())
, m_y1(tilePos1.y())
, m_x2(tilePos2.x())
, m_y2(tilePos2.y())
, m_tile1(tile1)
, m_tile2(tile2)
, m_hasSlide(true)
, m_slideX1(slideX1)
, m_slideY1(slideY1)
, m_slideX2(slideX2)
, m_slideY2(slideY2)
{
}
int Move::x1() const
{
return m_x1;
}
int Move::y1() const
{
return m_y1;
}
int Move::x2() const
{
return m_x2;
}
int Move::y2() const
{
return m_y2;
}
int Move::tile1() const
{
return m_tile1;
}
int Move::tile2() const
{
return m_tile2;
}
int Move::hasSlide() const
{
return m_hasSlide;
}
int Move::slideX1() const
{
return m_slideX1;
}
int Move::slideY1() const
{
return m_slideY1;
}
int Move::slideX2() const
{
return m_slideX2;
}
int Move::slideY2() const
{
return m_slideY2;
}
void Move::swapTiles()
{
std::swap(m_x1, m_x2);
std::swap(m_y1, m_y2);
std::swap(m_tile1, m_tile2);
}
// vim: expandtab:tabstop=4:shiftwidth=4
// kate: space-indent on; indent-width 4
/***************************************************************************
* KShisen - A japanese game similar to mahjongg *
* Copyright 2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "types.h"
#ifndef MOVE_H
#define MOVE_H
/**
* @brief Class holding a move on the board made by the player
*
* Contains all the information needed to undo or redo a move.
*/
class Move
{
public:
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile);
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2);
Move(TilePos const & tilePos1, TilePos const & tilePos2, int tile1, int tile2, int slideX1, int slideY1, int slideX2, int slideY2);
int x1() const;
int y1() const;
int x2() const;
int y2() const;
int tile1() const;
int tile2() const;
int hasSlide() const;
int slideX1() const;
int slideY1() const;
int slideX2() const;
int slideY2() const;
/**
* @brief Swaps the two tiles involved in a move.
*
* This is needed for undoing a move in case both tiles are in the same column.
*/
void swapTiles();
private:
int m_x1, m_y1, m_x2, m_y2; ///< coordinates of the two tiles that matched
int m_tile1; ///< type of tile at first set of coordinates
int m_tile2; ///< type of tile at second set of coordinates
bool m_hasSlide; ///< if we performed a slide during the move
int m_slideX1; ///< original x coordinate of the last slided tile
int m_slideY1; ///< original y coordinate of the last slided tile
int m_slideX2; ///< final x coordinate of the last slided tile
int m_slideY2; ///< final y coordinate of the last slided tile
};
#endif // MOVE_H
// vim: expandtab:tabstop=4:shiftwidth=4
// kate: space-indent on; indent-width 4
/***************************************************************************
* KShisen - A japanese game similar to mahjongg *
* Copyright 2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
// own
#include "possiblemove.h"
// KShisen
#include "debug.h"
PossibleMove::PossibleMove(Path & path)
: m_path(path)
, m_hasSlide(false)
, m_slide()
{
}
PossibleMove::PossibleMove(Path & path, Path & slide)
: m_path(path)
, m_hasSlide(true)
, m_slide(slide)
{
}
bool PossibleMove::isInPath(TilePos const & tilePos) const
{
if (tilePos.x() == m_path.back().x() && tilePos.y() == m_path.back().y()) {
return false;
}
qCDebug(KSHISEN_LOG) << "isInPath:" << tilePos.x() << "," << tilePos.y();
Debug();
// a path has at least 2 positions
auto iter = m_path.cbegin();
int pathX = iter->x();
int pathY = iter->y();
++iter;
for (; iter != m_path.cend(); ++iter) {
// to fix
if ((tilePos.x() == iter->x() && ((tilePos.y() > pathY && tilePos.y() <= iter->y())
|| (tilePos.y() < pathY && tilePos.y() >= iter->y())))
|| (tilePos.y() == iter->y() && ((tilePos.x() > pathX && tilePos.x() <= iter->x())
|| (tilePos.x() < pathX && tilePos.x() >= iter->x())))) {
qCDebug(KSHISEN_LOG) << "isInPath:" << tilePos.x() << "," << tilePos.y() << "found in path" << pathX << "," << pathY << " => " << iter->x() << "," << iter->y();
return true;
}
pathX = iter->x();
pathY = iter->y();
}
return false;
}
void PossibleMove::Debug() const
{
qCDebug(KSHISEN_LOG) << "PossibleMove";
foreach (auto iter, m_path) {
qCDebug(KSHISEN_LOG) << " Path:" << iter.x() << "," << iter.y();
}
if (m_hasSlide) {
qCDebug(KSHISEN_LOG) << " hasSlide";
foreach (auto iter, m_slide) {
qCDebug(KSHISEN_LOG) << " Slide:" << iter.x() << "," << iter.y();
}
}
}
Path PossibleMove::path() const
{
return m_path;
}
bool PossibleMove::hasSlide() const
{
return m_hasSlide;
}
Path PossibleMove::slide() const
{
return m_slide;
}
// vim: expandtab:tabstop=4:shiftwidth=4
// kate: space-indent on; indent-width 4
/***************************************************************************
* KShisen - A japanese game similar to mahjongg *
* Copyright 2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef POSSIBLEMOVE_H
#define POSSIBLEMOVE_H
#include "types.h"
/**
* @brief Class holding a possible move and its functions
*
* A PossibleMove is a connection Path between two tiles
* and optionally a slide Path.
* Sometimes for a couple of tiles to match there may be multiple
* possible moves for the player to choose between.
*/
class PossibleMove
{
public:
explicit PossibleMove(Path & path);
PossibleMove(Path & path, Path & slide);
bool isInPath(TilePos const & tilePos) const;
void Debug() const;
Path path() const;
bool hasSlide() const;
Path slide() const;
private:
Path m_path; ///< path used to connect the two tiles
bool m_hasSlide; ///< flag set if the move requires a slide
Path m_slide; ///< path representing the movement of the last sliding tile
};
#endif // POSSIBLEMOVE_H
// vim: expandtab:tabstop=4:shiftwidth=4
// kate: space-indent on; indent-width 4
/***************************************************************************
* KShisen - A japanese game similar to mahjongg *
* Copyright 2016 Frederik Schwarzer <schwarzer@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef TYPES_H
#define TYPES_H
#include <QList>
#include <QPoint>
using TilePos = QPoint;
/**
* A list of positions (at least 2) makes a Path
*/
using Path = QList<TilePos>;
#endif // TYPES_H
// vim: expandtab:tabstop=4:shiftwidth=4
// kate: space-indent on; indent-width 4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment