[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdots] /: KDots core refactoring.
From: Minh Ngo <nlminhtl () gmail ! com>
Date: 2014-12-31 17:32:55
Message-ID: E1Y6N8h-0005pl-L0 () scm ! kde ! org
[Download RAW message or body]
Git commit 38fdbe6e00398d980c5f4d7f97fdfc8b504baf49 by Minh Ngo.
Committed on 31/12/2014 at 00:23.
Pushed by minhngo into branch 'master'.
KDots core refactoring.
BoardModel owns IRival and IBoardView instances now. Adding space
after if, for, switch etc. #ifdef has been changed to #pragma once.
IPConnect is temporary turned off (some crash was detected).
... and other minor changes.
M +2 -0 CMakeLists.txt
M +20 -0 boardmodel.cpp
M +10 -0 boardmodel.hpp
M +44 -53 boardview.cpp
M +9 -8 boardview.hpp
M +1 -1 brushcombo.cpp
M +2 -5 brushcombo.hpp
M +1 -1 brushcombodelegate.cpp
M +2 -5 brushcombodelegate.hpp
M +2 -5 constants.hpp
M +6 -7 edgelist.hpp
M +2 -2 gameconfig.cpp
M +9 -10 gameconfig.hpp
M +10 -10 graph.hpp
C +31 -23 graphpoint.cpp [from: newgamewidget.hpp - 071% similarity]
M +14 -39 graphpoint.hpp
C +7 -10 iboardview.hpp [from: brushcombo.hpp - 085% similarity]
M +2 -5 interface/iconfigurationwidget.hpp
M +3 -5 interface/iplugin.hpp
M +7 -14 interface/irival.hpp
M +47 -94 mainwindow.cpp
M +13 -11 mainwindow.hpp
M +26 -29 newgamedialog.cpp
M +17 -14 newgamedialog.hpp
M +3 -7 newgamewidget.hpp
M +6 -7 pluginmanagerwidget.hpp
M +1 -1 plugins/CMakeLists.txt
M +2 -2 plugins/ipconnect/plugin.hpp
M +5 -5 plugins/ipconnect/rival.cpp
M +2 -2 plugins/ipconnect/rival.hpp
M +2 -2 plugins/simpleai/plugin.hpp
M +29 -30 plugins/simpleai/rival.cpp
M +4 -7 plugins/simpleai/rival.hpp
M +2 -2 plugins/singlepc/plugin.hpp
M +9 -3 pluginwidgetdelegate.cpp
M +4 -10 pluginwidgetdelegate.hpp
M +2 -2 point.cpp
M +5 -10 point.hpp
M +11 -13 polygon.cpp
M +9 -10 polygon.hpp
M +6 -7 polygonfinder.cpp
M +11 -12 polygonfinder.hpp
M +78 -5 stepqueue.cpp
M +22 -76 stepqueue.hpp
http://commits.kde.org/kdots/38fdbe6e00398d980c5f4d7f97fdfc8b504baf49
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12302ce..ca4c1e6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,7 @@ ENDIF(UNIX)
SET(KDOTSLIB_SRCS
point.cpp
+ graphpoint.cpp
graph.cpp
boardmodel.cpp
stepqueue.cpp
@@ -67,6 +68,7 @@ SET(KDOTSLIB_HEADERS
polygon.hpp
polygonfinder.hpp
gameconfig.hpp
+ iboardview.hpp
)
SET(SRCS
diff --git a/boardmodel.cpp b/boardmodel.cpp
index 985fc75..400bd5e 100644
--- a/boardmodel.cpp
+++ b/boardmodel.cpp
@@ -27,9 +27,11 @@
#include <KMessageBox>
#include <KLocalizedString>
#include <KDebug>
+#include <interface/irival.hpp>
#include "graph.hpp"
#include "polygonfinder.hpp"
#include "stepqueue.hpp"
+#include "boardview.hpp"
namespace KDots
{
@@ -41,6 +43,24 @@ namespace KDots
{
}
+ void BoardModel::setView(std::unique_ptr<IBoardView>&& view)
+ {
+ m_view = std::move(view);
+ m_view->setModel(this);
+ }
+
+ void BoardModel::setRival(std::unique_ptr<IRival>&& rival)
+ {
+ m_rival = std::move(rival);
+
+ connect(this, SIGNAL(nextPlayer(const Point&)), m_rival.get(), \
SLOT(nextStep(const Point&))); + }
+
+ IRival& BoardModel::rival() const
+ {
+ return *m_rival;
+ }
+
const GameConfig& BoardModel::gameConfig() const
{
return m_config;
diff --git a/boardmodel.hpp b/boardmodel.hpp
index d063503..246ca44 100644
--- a/boardmodel.hpp
+++ b/boardmodel.hpp
@@ -33,12 +33,17 @@ namespace KDots
{
class Graph;
class StepQueue;
+ class IBoardView;
+ class IRival;
class KDOTS_EXPORT BoardModel : public QObject
{
Q_OBJECT
public:
BoardModel(const GameConfig& config, std::shared_ptr<StepQueue> step_queue, \
QObject *parent = 0);
+ void setView(std::unique_ptr<IBoardView>&& view);
+ void setRival(std::unique_ptr<IRival>&& rival);
+
const GameConfig& gameConfig() const;
void pushPoint(const Point& point);
@@ -49,6 +54,8 @@ namespace KDots
const StepQueue& stepQueue() const;
+ IRival& rival() const;
+
void undo();
signals:
@@ -60,6 +67,9 @@ namespace KDots
void continueStep();
private:
+ std::unique_ptr<IBoardView> m_view;
+ std::unique_ptr<IRival> m_rival;
+
std::unique_ptr<Graph> m_graph;
std::shared_ptr<StepQueue> m_steps;
GameConfig m_config;
diff --git a/boardview.cpp b/boardview.cpp
index d49bfb3..7958e32 100644
--- a/boardview.cpp
+++ b/boardview.cpp
@@ -40,38 +40,30 @@
namespace KDots
{
- BoardView::BoardView(const GameConfig& config, QWidget *parent)
- : QWidget(parent)
- , m_table(nullptr)
- , m_height(config.m_height + 1)
- , m_width(config.m_width + 1)
+ BoardView::BoardView(QWidget *parent)
+ : IBoardView(parent)
+ , m_model(nullptr)
+ , m_height(0)
+ , m_width(0)
{
setMinimumSize(400, 400);
setMouseTracking(true);
}
- void BoardView::setModel(std::shared_ptr<BoardModel>& table)
+ void BoardView::setModel(BoardModel *model)
{
- m_table = table;
+ m_model = model;
- connect(m_table.get(),
- SIGNAL(nextPlayer(const Point&)),
- this,
- SLOT(update()));
- connect(m_table.get(),
- SIGNAL(nextPlayer(const Point&)),
- this,
- SLOT(onStatusMessage()));
+ connect(m_model, SIGNAL(nextPlayer(const Point&)), this, SLOT(update()));
+ connect(m_model, SIGNAL(nextPlayer(const Point&)), this, \
SLOT(onStatusMessage())); +
+ m_height = m_model->gameConfig().m_height + 1;
+ m_width = m_model->gameConfig().m_width + 1;
}
- void BoardView::setRival(std::shared_ptr<IRival>& rival)
- {
- m_rival = rival;
- }
-
namespace
{
- float cell_size(const QRect& rectange, int height, int width)
+ float calculateCellSize(const QRect& rectange, int height, int width)
{
const float cellHeight = rectange.height() / height;
const float cellWidth = rectange.width() / width;
@@ -82,12 +74,12 @@ namespace KDots
void BoardView::calculatePoint(Point& point, QMouseEvent *event)
{
- if(!m_rival->isAllow())
+ if (!m_model->rival().isAllow())
return;
const QRect& rectange = rect();
- const float cellSize = cell_size(rectange, m_height, m_width);
+ const float cellSize = calculateCellSize(rectange, m_height, m_width);
float dx =(rectange.width() - cellSize * m_width) / 2;
@@ -103,20 +95,19 @@ namespace KDots
dx = event->x() - dx - x * cellSize;
- if(dx > firstPart && dx < lastPart)
+ if (dx > firstPart && dx < lastPart)
return;
- else if(dx < firstPart)
+ else if (dx < firstPart)
--x;
dy = event->y() - dy - y * cellSize;
- if(dy > firstPart && dy < lastPart)
+ if (dy > firstPart && dy < lastPart)
return;
- else if(dy < firstPart)
+ else if (dy < firstPart)
--y;
- if(x >= m_width - 1 || x < 0
- || y < 0 || y >= m_height - 1)
+ if (x >= m_width - 1 || x < 0 || y < 0 || y >= m_height - 1)
return;
point.m_x = x;
@@ -130,16 +121,16 @@ namespace KDots
const bool needRepaint =(point != m_underMousePoint);
m_underMousePoint = point;
- if(needRepaint)
+ if (needRepaint)
update();
}
void BoardView::onStatusMessage()
{
- emit updateStatusBar(QString("First:\t")
- + QString::number(m_table->stepQueue().getMarks(Owner::FIRST))
+ emit statusUpdated(QString("First:\t")
+ + QString::number(m_model->stepQueue().getMarks(Owner::FIRST))
+ "\tSecond:\t"
- + QString::number(m_table->stepQueue().getMarks(Owner::SECOND)));
+ + QString::number(m_model->stepQueue().getMarks(Owner::SECOND)));
}
void BoardView::mousePressEvent(QMouseEvent *event)
@@ -147,14 +138,14 @@ namespace KDots
Point point;
calculatePoint(point, event);
- if(!point.empty())
- m_table->pushPoint(point);
+ if (!point.empty())
+ m_model->pushPoint(point);
}
void BoardView::undo()
{
setUpdatesEnabled(false);
- m_table->undo();
+ m_model->undo();
setUpdatesEnabled(true);
}
@@ -166,12 +157,12 @@ namespace KDots
const QBrush firstBrush(firstColor), secondBrush(secondColor);
const QPen firstPen(firstColor, 1.5), secondPen(secondColor, 1.5);
- const Graph& graph = m_table->graph();
+ const Graph& graph = m_model->graph();
- for(Graph::const_iterator itr = graph.begin(), itrEnd = graph.end();
- itr != itrEnd; ++itr)
+ for (Graph::const_iterator itr = graph.begin(), itrEnd = graph.end();
+ itr != itrEnd; ++itr)
{
- if(itr->owner() == Owner::NONE)
+ if (itr->owner() == Owner::NONE)
continue;
painter.setPen(itr->owner() == Owner::FIRST
@@ -188,7 +179,7 @@ namespace KDots
const GraphPoint::GraphEdges& edges = itr->edges();
- for(int j = 0; j < edges.size(); ++j)
+ for (int j = 0; j < edges.size(); ++j)
{
const Point& lastPoint = edges[j] + 1;
@@ -199,14 +190,14 @@ namespace KDots
void BoardView::drawLastPoint(QPainter& painter, float cellSize)
{
- const Graph& graph = m_table->graph();
- const Point& lastPoint = m_table->stepQueue().lastPoint();
+ const Graph& graph = m_model->graph();
+ const Point& lastPoint = m_model->stepQueue().lastPoint();
const QColor firstColor(Settings::firstPointColor());
const QColor secondColor(Settings::secondPointColor());
const QPen firtBorder(firstColor, 0.5), secondBorder(secondColor, 0.5);
- if(!lastPoint.empty())
+ if (!lastPoint.empty())
{
painter.setPen(graph[lastPoint].owner() == Owner::FIRST
? firtBorder
@@ -217,8 +208,8 @@ namespace KDots
painter.drawEllipse(QPointF(newPoint) * cellSize, 6, 6);
}
- const std::vector<Point>& possiblePoints = m_rival->possibleMoves();
- for(const Point& point : possiblePoints)
+ const std::vector<Point>& possiblePoints = m_model->rival().possibleMoves();
+ for (const Point& point : possiblePoints)
{
painter.setPen(Qt::gray);
@@ -230,10 +221,10 @@ namespace KDots
void BoardView::drawUnderMousePoint(QPainter& painter, float cellSize)
{
- if(m_underMousePoint.empty())
+ if (m_underMousePoint.empty())
return;
- const Graph& graph = m_table->graph();
+ const Graph& graph = m_model->graph();
const QColor firstColor(Settings::firstPointColor());
const QColor secondColor(Settings::secondPointColor());
@@ -254,14 +245,14 @@ namespace KDots
const QColor firstColor(Settings::firstPointColor());
const QColor secondColor(Settings::secondPointColor());
- const auto& polygonVector = m_table->polygons();
+ const auto& polygonVector = m_model->polygons();
const QBrush firstPolyBrush(firstColor,
BrushComboDelegate::getBrushStyle(Settings::firstFillStyle()));
const QBrush secondPolyBrush(secondColor,
BrushComboDelegate::getBrushStyle(Settings::secondFillStyle()));
- for(Polygon_ptr polygon : polygonVector)
+ for (Polygon_ptr polygon : polygonVector)
{
QPolygon qPoly;
for(const Point& point : polygon->points())
@@ -280,7 +271,7 @@ namespace KDots
void BoardView::paintEvent(QPaintEvent *event)
{
const QRect& rectange = event->rect();
- const float cellSize = cell_size(rectange, m_height, m_width);
+ const float cellSize = calculateCellSize(rectange, m_height, m_width);
const float tableWidth = cellSize * m_width;
const float tableHeight = cellSize * m_height;
@@ -292,10 +283,10 @@ namespace KDots
pixPainter.setRenderHint(QPainter::Antialiasing);
pixPainter.setPen(QPen(Qt::black, 1));
- for(int i = cellSize, k = m_width * cellSize; i < k; i += cellSize)
+ for (int i = cellSize, k = m_width * cellSize; i < k; i += cellSize)
pixPainter.drawLine(i, 0, i, pixmap.height());
- for(int i = cellSize, k = m_height * cellSize; i < k; i += cellSize)
+ for (int i = cellSize, k = m_height * cellSize; i < k; i += cellSize)
pixPainter.drawLine(0, i, pixmap.width(), i);
pixPainter.setPen(QPen(Qt::black, 3));
diff --git a/boardview.hpp b/boardview.hpp
index a6900d7..eec9f99 100644
--- a/boardview.hpp
+++ b/boardview.hpp
@@ -25,7 +25,7 @@
*/
#pragma once
#include <memory>
-#include <QWidget>
+#include "iboardview.hpp"
#include "constants.hpp"
#include "point.hpp"
@@ -37,14 +37,16 @@ namespace KDots
class BoardModel;
struct GameConfig;
- class BoardView : public QWidget
+ class BoardView : public IBoardView
{
Q_OBJECT
public:
- BoardView(const GameConfig& config, QWidget *parent = 0);
+ BoardView(QWidget *parent = 0);
+
+ void setModel(BoardModel *table);
+
+ public slots:
void undo();
- void setModel(std::shared_ptr<BoardModel>& table);
- void setRival(std::shared_ptr<IRival>& rival);
protected:
void mousePressEvent(QMouseEvent *event);
@@ -62,11 +64,10 @@ namespace KDots
void onStatusMessage();
signals:
- void updateStatusBar(const QString& msg);
+ void statusUpdated(const QString& msg);
private:
- std::shared_ptr<BoardModel> m_table;
- std::shared_ptr<IRival> m_rival;
+ BoardModel *m_model;
int m_height;
int m_width;
diff --git a/brushcombo.cpp b/brushcombo.cpp
index 56d2ce5..a6cce68 100644
--- a/brushcombo.cpp
+++ b/brushcombo.cpp
@@ -33,7 +33,7 @@ namespace KDots
BrushCombo::BrushCombo(QWidget* parent)
: KComboBox(parent)
{
- for(int i = 0; i < 15; ++i)
+ for (int i = 0; i < 15; ++i)
addItem(QString::number(i));
setItemDelegate(new BrushComboDelegate(this));
diff --git a/brushcombo.hpp b/brushcombo.hpp
index 94e1b4f..22bcbe6 100644
--- a/brushcombo.hpp
+++ b/brushcombo.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_BRUSHCOMBO_HPP
-#define KDOTS_BRUSHCOMBO_HPP
+#pragma once
#include <KComboBox>
#include "constants.hpp"
@@ -36,6 +35,4 @@ namespace KDots
BrushCombo(QWidget* parent = 0);
void paintEvent(QPaintEvent *e);
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/brushcombodelegate.cpp b/brushcombodelegate.cpp
index d25459a..3645821 100644
--- a/brushcombodelegate.cpp
+++ b/brushcombodelegate.cpp
@@ -57,7 +57,7 @@ namespace KDots
const QStyleOptionViewItem&, const QModelIndex&) const
{
QComboBox* editor = new QComboBox(parent);
- for(int i = 0, size = brushes().size(); i < size; ++i)
+ for (int i = 0, size = brushes().size(); i < size; ++i)
editor->addItem(QString::number(i));
return editor;
diff --git a/brushcombodelegate.hpp b/brushcombodelegate.hpp
index 0579a44..fb7ba4a 100644
--- a/brushcombodelegate.hpp
+++ b/brushcombodelegate.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_BRUSHCOMBODELEGATE_HPP
-#define KDOTS_BRUSHCOMBODELEGATE_HPP
+#pragma once
#include <QStyledItemDelegate>
#include <QVector>
@@ -49,6 +48,4 @@ namespace KDots
const QModelIndex& index) const;
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) \
const; };
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/constants.hpp b/constants.hpp
index 4897bc9..c48655a 100644
--- a/constants.hpp
+++ b/constants.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_CONSTANTS_HPP
-#define KDOTS_CONSTANTS_HPP
+#pragma once
#include <QString>
#include <kdemacros.h>
#ifndef KDOTS_EXPORT
@@ -62,6 +61,4 @@ namespace KDots
const int GRAPH_DY[DIRECTION_COUNT] = {1, 1, 0, -1, -1, -1, 0, 1};
const QString PLUGIN_SUFFIX = "kdots_";
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/edgelist.hpp b/edgelist.hpp
index dfb8619..35f47e5 100644
--- a/edgelist.hpp
+++ b/edgelist.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_EDGELIST_HPP
-#define KDOTS_EDGELIST_HPP
+#pragma once
#include <stdexcept>
#include "point.hpp"
@@ -33,8 +32,6 @@ namespace KDots
template<int SIZE>
class KDOTS_EXPORT EdgeList final
{
- int m_count;
- Point m_pointList[SIZE];
public:
EdgeList()
: m_count(0)
@@ -94,7 +91,9 @@ namespace KDots
return false;
}
+
+ private:
+ int m_count;
+ Point m_pointList[SIZE];
};
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/gameconfig.cpp b/gameconfig.cpp
index f5805f2..d97552f 100644
--- a/gameconfig.cpp
+++ b/gameconfig.cpp
@@ -27,14 +27,14 @@
QDataStream& operator<<(QDataStream& out, const KDots::GameConfig& obj)
{
- out <<(quint32) obj.m_firstOwner <<(quint32) obj.m_height <<(quint32) obj.m_width \
<<(quint32) obj.m_mode; + out << (quint32) obj.m_firstOwner << (quint32) \
obj.m_height << (quint32) obj.m_width << (quint32) obj.m_mode; return out;
}
QDataStream& operator>>(QDataStream& in, KDots::GameConfig& obj)
{
quint32 owner, mode;
- in >> owner >>(quint32&) obj.m_height >>(quint32&) obj.m_width >> mode;
+ in >> owner >> (quint32&) obj.m_height >> (quint32&) obj.m_width >> mode;
obj.m_firstOwner = static_cast<KDots::Owner>(owner);
obj.m_mode = static_cast<KDots::GameMode>(mode);
return in;
diff --git a/gameconfig.hpp b/gameconfig.hpp
index d37981a..277a17c 100644
--- a/gameconfig.hpp
+++ b/gameconfig.hpp
@@ -23,25 +23,26 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_GAMECONFIG_HPP
-#define KDOTS_GAMECONFIG_HPP
+#pragma once
#include <QMetaType>
#include "constants.hpp"
#include "point.hpp"
namespace KDots
{
- struct KDOTS_EXPORT GameConfig final
+ class KDOTS_EXPORT GameConfig final
{
- int m_width, m_height;
- GameMode m_mode;
- Owner m_firstOwner;
-
+ public:
GameConfig();
bool isInititialized() const;
static void registerMeta();
+
+ public:
+ int m_width, m_height;
+ GameMode m_mode;
+ Owner m_firstOwner;
};
}
@@ -50,6 +51,4 @@ Q_DECLARE_METATYPE(KDots::GameConfig);
QDataStream& operator<<(QDataStream& out, const KDots::GameConfig& obj);
-QDataStream& operator>>(QDataStream& in, KDots::GameConfig& obj);
-
-#endif
\ No newline at end of file
+QDataStream& operator>>(QDataStream& in, KDots::GameConfig& obj);
\ No newline at end of file
diff --git a/graph.hpp b/graph.hpp
index 626829b..0da68a2 100644
--- a/graph.hpp
+++ b/graph.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_GRAPH_HPP
-#define KDOTS_GRAPH_HPP
+#pragma once
#include <vector>
#include <iterator>
#include "graphpoint.hpp"
@@ -38,7 +37,6 @@ namespace KDots
class KDOTS_EXPORT Graph final
{
- std::vector<std::vector<GraphPoint>> m_graph;
public:
typedef graph_iterator<GraphPoint> iterator;
typedef graph_iterator<const GraphPoint> const_iterator;
@@ -88,15 +86,15 @@ namespace KDots
void addEdge(const KDots::Point& first, const KDots::Point& second);
void removeEdge(const Point& first, const Point& second);
+
+ private:
+ std::vector<std::vector<GraphPoint>> m_graph;
};
template<class A>
class graph_iterator final : public std::iterator<std::forward_iterator_tag, A>
{
- Graph *m_graph;
- std::size_t m_x, m_y;
- public:
-
+ public:
Point point() const
{
return Point(m_x, m_y);
@@ -177,7 +175,9 @@ namespace KDots
++(*this);
return res;
}
+
+ private:
+ Graph *m_graph;
+ std::size_t m_x, m_y;
};
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/newgamewidget.hpp b/graphpoint.cpp
similarity index 71%
copy from newgamewidget.hpp
copy to graphpoint.cpp
index 5af4219..f4bcf22 100644
--- a/newgamewidget.hpp
+++ b/graphpoint.cpp
@@ -23,35 +23,43 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_NEWGAMEWIDGET_HPP
-#define KDOTS_NEWGAMEWIDGET_HPP
-#include <QWidget>
-#include "constants.hpp"
-#include "gameconfig.hpp"
-
-namespace Ui
-{
- class NewGameWidget;
-}
+#include "graphpoint.hpp"
namespace KDots
{
- class NewGameWidget : public QWidget
+ GraphPoint::GraphPoint(Owner owner)
+ : m_captured(false)
+ , m_owner(owner)
{
- public:
- NewGameWidget(QWidget *parent = 0);
+ }
- int getHeight() const;
- int getWidth() const;
- GameMode getGameMode() const;
- Owner getFirstMoving() const;
+ bool GraphPoint::isCaptured() const
+ {
+ return m_captured;
+ }
- GameConfig getGameConfig() const;
- private:
- Ui::NewGameWidget *m_ui;
- };
-}
+ void GraphPoint::capture()
+ {
+ m_captured = true;
+ }
+ void GraphPoint::setOwner(Owner owner)
+ {
+ m_owner = owner;
+ }
+ Owner GraphPoint::owner() const
+ {
+ return m_owner;
+ }
+
+ GraphPoint::GraphEdges& GraphPoint::edges()
+ {
+ return m_edges;
+ }
-#endif
+ const GraphPoint::GraphEdges& GraphPoint::edges() const
+ {
+ return m_edges;
+ }
+}
\ No newline at end of file
diff --git a/graphpoint.hpp b/graphpoint.hpp
index b34db87..1161649 100644
--- a/graphpoint.hpp
+++ b/graphpoint.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_GRAPHPOINT_HPP
-#define KDOTS_GRAPHPOINT_HPP
+#pragma once
#include "edgelist.hpp"
#include "constants.hpp"
@@ -35,48 +34,24 @@ namespace KDots
public:
typedef EdgeList<DIRECTION_COUNT> GraphEdges;
- private:
- bool m_captured;
- Owner m_owner;
- GraphEdges m_edges;
-
public:
- GraphPoint(Owner owner = Owner::NONE)
- : m_captured(false)
- , m_owner(owner)
- {
- }
+ GraphPoint(Owner owner = Owner::NONE);
- bool isCaptured() const
- {
- return m_captured;
- }
+ bool isCaptured() const;
- void capture()
- {
- m_captured = true;
- }
+ void capture();
- void setOwner(Owner owner)
- {
- m_owner = owner;
- }
+ void setOwner(Owner owner);
- Owner owner() const
- {
- return m_owner;
- }
+ Owner owner() const;
- GraphEdges& edges()
- {
- return m_edges;
- }
+ GraphEdges& edges();
- const GraphEdges& edges() const
- {
- return m_edges;
- }
+ const GraphEdges& edges() const;
+
+ private:
+ bool m_captured;
+ Owner m_owner;
+ GraphEdges m_edges;
};
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/brushcombo.hpp b/iboardview.hpp
similarity index 85%
copy from brushcombo.hpp
copy to iboardview.hpp
index 94e1b4f..daea0f2 100644
--- a/brushcombo.hpp
+++ b/iboardview.hpp
@@ -23,19 +23,16 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_BRUSHCOMBO_HPP
-#define KDOTS_BRUSHCOMBO_HPP
-#include <KComboBox>
-#include "constants.hpp"
+#pragma once
+#include <QWidget>
namespace KDots
{
- class BrushCombo : public KComboBox
+ class BoardModel;
+ class IBoardView : public QWidget
{
public:
- BrushCombo(QWidget* parent = 0);
- void paintEvent(QPaintEvent *e);
+ IBoardView(QWidget *parent = 0) : QWidget(parent) {}
+ virtual void setModel(BoardModel *table) = 0;
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/interface/iconfigurationwidget.hpp b/interface/iconfigurationwidget.hpp
index 730ad02..fa35f9f 100644
--- a/interface/iconfigurationwidget.hpp
+++ b/interface/iconfigurationwidget.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_ICONFIGURATIONWIDGET_HPP
-#define KDOTS_ICONFIGURATIONWIDGET_HPP
+#pragma once
#include <QWidget>
namespace KDots
@@ -43,6 +42,4 @@ namespace KDots
};
}
-Q_DECLARE_INTERFACE(KDots::IConfigurationWidget, \
"com.github.ignotus.kdots.IConfigurationWidget/1.0.1");
-
-#endif
\ No newline at end of file
+Q_DECLARE_INTERFACE(KDots::IConfigurationWidget, \
"com.github.ignotus.kdots.IConfigurationWidget/1.0.1"); \ No newline at end of file
diff --git a/interface/iplugin.hpp b/interface/iplugin.hpp
index 17fe2cc..dc57e65 100644
--- a/interface/iplugin.hpp
+++ b/interface/iplugin.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_IPLUGIN_HPP
-#define KDOTS_IPLUGIN_HPP
+#pragma once
#include <memory>
#include <QString>
#include <KIcon>
@@ -51,7 +50,7 @@ namespace KDots
*/
virtual QString description() const = 0;
- virtual std::shared_ptr<IRival> createRival() = 0;
+ virtual std::unique_ptr<IRival> createRival() = 0;
/** @brief Returns a plugin icon.
*/
@@ -63,5 +62,4 @@ namespace KDots
}
-Q_DECLARE_INTERFACE(KDots::IPlugin, "com.github.ignotus.kdots.IPlugin/1.0.1");
-#endif
+Q_DECLARE_INTERFACE(KDots::IPlugin, "com.github.ignotus.kdots.IPlugin/1.0.1");
\ No newline at end of file
diff --git a/interface/irival.hpp b/interface/irival.hpp
index e09627a..e31cbeb 100644
--- a/interface/irival.hpp
+++ b/interface/irival.hpp
@@ -23,14 +23,14 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_IRIVAL_HPP
-#define KDOTS_IRIVAL_HPP
+#pragma once
#include <memory>
#include <QObject>
#include <newgamewidget.hpp>
#include <point.hpp>
class QStatusBar;
+class KgDifficultyLevel;
namespace KDots
{
@@ -72,19 +72,14 @@ namespace KDots
Q_UNUSED(point);
}
- virtual void setBoardModel(std::shared_ptr<BoardModel>& table)
+ virtual void setBoardModel(BoardModel *board)
{
- Q_UNUSED(table);
+ Q_UNUSED(board);
}
- virtual void setStatusBar(QStatusBar *bar)
+ virtual void setDifficulty(const KgDifficultyLevel *difficulty)
{
- Q_UNUSED(bar);
- }
-
- virtual void setDifficulty(int diff)
- {
- Q_UNUSED(diff);
+ Q_UNUSED(difficulty);
}
virtual bool canUndo() const
@@ -99,6 +94,4 @@ namespace KDots
};
}
-Q_DECLARE_INTERFACE(KDots::IRival, "com.github.ignotus.kdots.IRival/1.0.1")
-
-#endif
\ No newline at end of file
+Q_DECLARE_INTERFACE(KDots::IRival, "com.github.ignotus.kdots.IRival/1.0.1")
\ No newline at end of file
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 842ea40..fe96bea 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -50,8 +50,6 @@ namespace KDots
MainWindow::MainWindow(QWidget *parent)
: KXmlGuiWindow(parent)
, m_ui(new Ui::MainWindow)
- , m_destroyTable(false)
- , m_table(nullptr)
{
m_ui->setupUi(this);
@@ -59,11 +57,6 @@ namespace KDots
Kg::difficulty()->addStandardLevel(KgDifficultyLevel::Medium);
Kg::difficulty()->addStandardLevel(KgDifficultyLevel::Hard);
- connect(Kg::difficulty(),
- SIGNAL(currentLevelChanged(const KgDifficultyLevel*)),
- this,
- SLOT(difficultyHandler(const KgDifficultyLevel*)));
-
KgDifficultyGUI::init(this);
Kg::difficulty()->setEditable(false);
@@ -72,74 +65,42 @@ namespace KDots
setupGUI(Default, "kdotsui.rc");
}
- void MainWindow::difficultyHandler(const KgDifficultyLevel *level)
- {
- int diff;
-
- switch(level->standardLevel())
- {
- case KgDifficultyLevel::Easy:
- diff = 1;
- case KgDifficultyLevel::Medium:
- diff = 2;
- default:
- diff = 3;
- }
-
- if(m_rival)
- m_rival->setDifficulty(diff);
- }
-
void MainWindow::initMenu()
{
KStandardAction::preferences(this, SLOT(onPreferences()), actionCollection());
- KAction *newAction = new KAction(KIcon("file_new"), i18n("&New game"), this);
- newAction->setShortcut(Qt::CTRL + Qt::Key_N);
+ m_menu.m_newAction = new KAction(KIcon("file_new"), i18n("&New game"), this);
+ m_menu.m_newAction->setShortcut(Qt::CTRL + Qt::Key_N);
- connect(newAction, SIGNAL(triggered(bool)), this, SLOT(onNewGame()));
+ connect(m_menu.m_newAction, SIGNAL(triggered(bool)), this, SLOT(onNewGame()));
- actionCollection()->addAction("NewGame", newAction);
-
- KAction *endAction = actionCollection()->addAction("EndGame", this, \
SLOT(endGame()));
- endAction->setIcon(KIcon("window-close"));
- endAction->setText(i18n("&End game"));
- endAction->setShortcut(Qt::CTRL + Qt::Key_E);
- endAction->setEnabled(false);
-
- KAction *quitAction = actionCollection()->addAction("Quit", this, \
SLOT(close()));
- quitAction->setIcon(KIcon("exit"));
- quitAction->setText(i18n("&Quit"));
- quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
-
- KAction *undoAction = actionCollection()->addAction("UndoGame", this, \
SLOT(undo()));
- undoAction->setIcon(KIcon("undo"));
- undoAction->setText(i18n("&Undo"));
- undoAction->setEnabled(false);
- undoAction->setShortcut(Qt::CTRL + Qt::Key_Z);
-
- connect(this, SIGNAL(endActionEnable(bool)), endAction, SLOT(setEnabled(bool)));
-
- connect(this, SIGNAL(undoActionEnable(bool)), undoAction, \
SLOT(setEnabled(bool))); + actionCollection()->addAction("NewGame", \
m_menu.m_newAction); +
+ m_menu.m_endAction = actionCollection()->addAction("EndGame", this, \
SLOT(endGame())); + m_menu.m_endAction->setIcon(KIcon("window-close"));
+ m_menu.m_endAction->setText(i18n("&End game"));
+ m_menu.m_endAction->setShortcut(Qt::CTRL + Qt::Key_E);
+ m_menu.m_endAction->setEnabled(false);
+
+ m_menu.m_quitAction = actionCollection()->addAction("Quit", this, \
SLOT(close())); + m_menu.m_quitAction->setIcon(KIcon("exit"));
+ m_menu.m_quitAction->setText(i18n("&Quit"));
+ m_menu.m_quitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
+
+ m_menu.m_undoAction = actionCollection()->addAction("UndoGame", this);
+ m_menu.m_undoAction->setIcon(KIcon("undo"));
+ m_menu.m_undoAction->setText(i18n("&Undo"));
+ m_menu.m_undoAction->setEnabled(false);
+ m_menu.m_undoAction->setShortcut(Qt::CTRL + Qt::Key_Z);
}
void MainWindow::endGame()
{
- m_table->deleteLater();
- m_table = nullptr;
- m_rival.reset();
-
- emit endActionEnable(false);
-
+ m_menu.m_endAction->setEnabled(false);
+ m_model.reset();
statusBar()->clearMessage();
}
- void MainWindow::undo()
- {
- if(m_table && m_rival && m_rival->canUndo())
- m_table->undo();
- }
-
void MainWindow::onPreferences()
{
KConfigDialog dialog(this, i18n("Preferences"), Settings::self());
@@ -151,10 +112,8 @@ namespace KDots
dialog.addPage(board, i18n("Board"), QLatin1String("games-config-options"));
- if (m_table)
- connect(&dialog, SIGNAL(accepted()), m_table, SLOT(update()));
-
- dialog.exec();
+ if (dialog.exec() == QDialog::Accepted)
+ emit preferencesUpdated();
}
namespace
@@ -179,42 +138,36 @@ namespace KDots
if (!config.isInititialized())
return;
- m_rival = dialog.rival();
- m_rival->setStatusBar(statusBar());
- difficultyHandler(Kg::difficulty()->currentLevel());
- emit undoActionEnable(m_rival->canUndo());
-
- connect(m_rival.get(), SIGNAL(needDestroy()), this, SLOT(destroyGame()));
-
- m_table = new BoardView(config, this);
+ auto rival = std::move(dialog.rival());
- auto model = std::make_shared<BoardModel>(config, createStepQueue(config));
+ connect(Kg::difficulty(),
+ SIGNAL(currentLevelChanged(const KgDifficultyLevel*)),
+ rival.get(),
+ SLOT(setDifficulty(const KgDifficultyLevel*)));
- m_rival->setBoardModel(model);
+ m_menu.m_undoAction->setEnabled(rival->canUndo());
- connect(model.get(), SIGNAL(nextPlayer(const Point&)), m_rival.get(), \
SLOT(nextStep(const Point&))); + connect(rival.get(), SIGNAL(needDestroy()), this, \
SLOT(endGame()));
- m_table->setModel(model);
- m_table->setRival(m_rival);
+ m_model = std::unique_ptr<BoardModel>(new BoardModel(config, \
createStepQueue(config)));
- if(m_destroyTable)
{
- endGame();
- return;
- }
-
- connect(m_table, SIGNAL(updateStatusBar(const QString&)), statusBar(), \
SLOT(showMessage(const QString&))); + std::unique_ptr<IBoardView> view(new \
BoardView(this)); +
+ connect(view.get(), SIGNAL(statusUpdated(const QString&)), statusBar(), \
SLOT(showMessage(const QString&))); + connect(this, SIGNAL(preferencesUpdated()), \
view.get(), SLOT(update()));
- setCentralWidget(m_table);
- m_table->show();
+ connect(m_menu.m_undoAction, SIGNAL(triggered(bool)), view.get(), SLOT(undo()));
- emit endActionEnable(true);
- }
-
- void MainWindow::destroyGame()
- {
- m_destroyTable = true;
- emit undoActionEnable(false);
+ setCentralWidget(view.get());
+
+ m_model->setView(std::move(view));
+ }
+
+ rival->setBoardModel(m_model.get());
+ m_model->setRival(std::move(rival));
+
+ m_menu.m_endAction->setEnabled(true);
}
}
diff --git a/mainwindow.hpp b/mainwindow.hpp
index 8d5d9c0..48fe785 100644
--- a/mainwindow.hpp
+++ b/mainwindow.hpp
@@ -38,7 +38,7 @@ class KAction;
namespace KDots
{
- class BoardView;
+ class BoardModel;
class IRival;
class MainWindow : public KXmlGuiWindow
@@ -52,20 +52,22 @@ namespace KDots
private slots:
void onNewGame();
- void destroyGame();
void onPreferences();
- void undo();
void endGame();
- void difficultyHandler(const KgDifficultyLevel *level);
-
+
signals:
- void undoActionEnable(bool);
- void endActionEnable(bool);
-
+ void preferencesUpdated();
+
private:
Ui::MainWindow *m_ui;
- std::shared_ptr<IRival> m_rival;
- bool m_destroyTable;
- BoardView *m_table;
+ std::unique_ptr<BoardModel> m_model;
+
+ struct
+ {
+ KAction *m_newAction;
+ KAction *m_endAction;
+ KAction *m_quitAction;
+ KAction *m_undoAction;
+ } m_menu;
};
}
\ No newline at end of file
diff --git a/newgamedialog.cpp b/newgamedialog.cpp
index dd8782f..a5fed5a 100644
--- a/newgamedialog.cpp
+++ b/newgamedialog.cpp
@@ -47,36 +47,41 @@ namespace KDots
m_ui->Grid->addWidget(m_pluginManager, 0, 0);
- connect(m_ui->NextButton,
- SIGNAL(clicked(bool)),
- this,
- SLOT(pluginWidget()));
+ connect(m_ui->NextButton, SIGNAL(clicked(bool)), this, SLOT(pluginWidget()));
+ m_ui->NextButton->setFocus();
}
NewGameDialog::~NewGameDialog()
{
- if(m_configWidget)
+ if (m_configWidget)
m_configWidget->setParent(0);
}
- std::shared_ptr<IRival> NewGameDialog::rival() const
+ std::unique_ptr<IRival> NewGameDialog::rival()
{
- return m_rival;
+ return std::move(m_rival);
}
- GameConfig NewGameDialog::gameConfig() const
+ void NewGameDialog::accept()
{
- if(m_game)
- return m_game->getGameConfig();
+ if (m_game)
+ m_config = m_game->getGameConfig();
+ else
+ m_config = m_rival->getGameConfig();
- return m_rival->getGameConfig();
+ QDialog::accept();
+ }
+
+ const GameConfig& NewGameDialog::gameConfig() const
+ {
+ return m_config;
}
void NewGameDialog::pluginWidget()
{
m_ui->NextButton->disconnect(this, SLOT(pluginWidget()));
- if(!m_pluginManager)
+ if (!m_pluginManager)
{
kWarning() << "Cannot cast to PluginManagerWidget";
return;
@@ -85,19 +90,19 @@ namespace KDots
const QString& pluginName = m_pluginManager->pluginName();
IPlugin *pluginInstance = PluginLoader::instance().plugin(pluginName);
- if(!pluginInstance)
+ if (!pluginInstance)
{
kDebug() << "Plugin instance not exists";
return;
}
- m_rival = pluginInstance->createRival();
+ m_rival = std::move(pluginInstance->createRival());
m_pluginManager->hide();
m_configWidget = m_rival->configureWidget();
- if(!m_configWidget)
+ if (!m_configWidget)
{
gameWidget();
return;
@@ -105,27 +110,18 @@ namespace KDots
m_ui->Grid->addWidget(m_configWidget , 0, 0);
- connect(m_configWidget,
- SIGNAL(needCreateTable(bool)),
- this,
- SLOT(onNeedCreateTable(bool)));
+ connect(m_configWidget, SIGNAL(needCreateTable(bool)), this, \
SLOT(onNeedCreateTable(bool)));
- connect(m_ui->NextButton,
- SIGNAL(clicked(bool)),
- this,
- SLOT(gameWidget()));
+ connect(m_ui->NextButton, SIGNAL(clicked(bool)), this, SLOT(gameWidget()));
}
void NewGameDialog::onNeedCreateTable(bool val)
{
- if(val)
+ if (val)
{
m_ui->NextButton->setEnabled(true);
m_ui->OKButton->setEnabled(false);
- connect(m_ui->NextButton,
- SIGNAL(clicked(bool)),
- this,
- SLOT(gameWidget()));
+ connect(m_ui->NextButton, SIGNAL(clicked(bool)), this, SLOT(gameWidget()));
}
else
{
@@ -137,11 +133,12 @@ namespace KDots
void NewGameDialog::gameWidget()
{
- if(m_configWidget)
+ if (m_configWidget)
m_configWidget->hide();
m_ui->NextButton->setEnabled(false);
m_ui->OKButton->setEnabled(true);
+ m_ui->OKButton->setFocus();
m_game = new NewGameWidget(this);
m_ui->Grid->addWidget(m_game, 0, 0);
}
diff --git a/newgamedialog.hpp b/newgamedialog.hpp
index f305df0..60cc6a8 100644
--- a/newgamedialog.hpp
+++ b/newgamedialog.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_NEWGAMEDIALOG_HPP
-#define KDOTS_NEWGAMEDIALOG_HPP
+#pragma once
#include <memory>
#include <QDialog>
#include "gameconfig.hpp"
@@ -44,25 +43,29 @@ namespace KDots
class NewGameDialog : public QDialog
{
Q_OBJECT
-
- Ui::NewGameDialog *m_ui;
- NewGameWidget *m_game;
- PluginManagerWidget *m_pluginManager;
- IConfigurationWidget *m_configWidget;
-
- mutable std::shared_ptr<IRival> m_rival;
public:
NewGameDialog(QWidget *parent = 0);
~NewGameDialog();
- std::shared_ptr<IRival> rival() const;
+ std::unique_ptr<IRival> rival();
+
+ const GameConfig& gameConfig() const;
+
+ public:
+ void accept();
- GameConfig gameConfig() const;
private slots:
void pluginWidget();
void gameWidget();
void onNeedCreateTable(bool);
+
+ private:
+ Ui::NewGameDialog *m_ui;
+ NewGameWidget *m_game;
+ PluginManagerWidget *m_pluginManager;
+ IConfigurationWidget *m_configWidget;
+
+ std::unique_ptr<IRival> m_rival;
+ GameConfig m_config;
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/newgamewidget.hpp b/newgamewidget.hpp
index 5af4219..4f13a95 100644
--- a/newgamewidget.hpp
+++ b/newgamewidget.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_NEWGAMEWIDGET_HPP
-#define KDOTS_NEWGAMEWIDGET_HPP
+#pragma once
#include <QWidget>
#include "constants.hpp"
#include "gameconfig.hpp"
@@ -47,11 +46,8 @@ namespace KDots
Owner getFirstMoving() const;
GameConfig getGameConfig() const;
+
private:
Ui::NewGameWidget *m_ui;
};
-}
-
-
-
-#endif
+}
\ No newline at end of file
diff --git a/pluginmanagerwidget.hpp b/pluginmanagerwidget.hpp
index 5dc2200..e6851f7 100644
--- a/pluginmanagerwidget.hpp
+++ b/pluginmanagerwidget.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_PLUGINMANAGERWIDGET_HPP
-#define KDOTS_PLUGINMANAGERWIDGET_HPP
+#pragma once
#include <QWidget>
class QComboBox;
@@ -40,15 +39,15 @@ namespace KDots
class PluginManagerWidget : public QWidget
{
Q_OBJECT
-
- Ui::PluginManagerWidget *m_ui;
public:
PluginManagerWidget(QWidget *parent = 0);
QString pluginName() const;
+
private slots:
void onIndexChanged(const QModelIndex& current);
+
+ private:
+ Ui::PluginManagerWidget *m_ui;
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index ee41fb0..725a085 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,3 +1,3 @@
ADD_SUBDIRECTORY(singlepc)
-ADD_SUBDIRECTORY(ipconnect)
+#ADD_SUBDIRECTORY(ipconnect)
ADD_SUBDIRECTORY(simpleai)
\ No newline at end of file
diff --git a/plugins/ipconnect/plugin.hpp b/plugins/ipconnect/plugin.hpp
index 0b4c5d9..98a2f1c 100644
--- a/plugins/ipconnect/plugin.hpp
+++ b/plugins/ipconnect/plugin.hpp
@@ -42,9 +42,9 @@ namespace KDots
{
}
- std::shared_ptr<IRival> createRival()
+ std::unique_ptr<IRival> createRival()
{
- return std::shared_ptr<IRival>(new Rival);
+ return std::unique_ptr<IRival>(new Rival);
}
QString name() const
diff --git a/plugins/ipconnect/rival.cpp b/plugins/ipconnect/rival.cpp
index 2928289..4882b21 100644
--- a/plugins/ipconnect/rival.cpp
+++ b/plugins/ipconnect/rival.cpp
@@ -144,9 +144,9 @@ namespace KDots
return GameConfig();
}
- void Rival::setBoardModel(std::shared_ptr<BoardModel>& table) //Is called after \
configureWidget + void Rival::setBoardModel(BoardModel *board) //Is called after \
configureWidget {
- m_table = table;
+ m_board = board;
ServerConfig config;
if(!m_configWidget->serverConfig(config))
@@ -184,7 +184,7 @@ namespace KDots
bool Rival::isAllow() const
{
- return m_table->stepQueue().getCurrentOwner() == m_me;
+ return m_board->stepQueue().getCurrentOwner() == m_me;
}
void Rival::nextStep(const Point& point)
@@ -208,7 +208,7 @@ namespace KDots
QByteArray gameData;
QDataStream out(&gameData, QIODevice::WriteOnly);
- out << QVariant::fromValue<GameConfig>(m_table->gameConfig())
+ out << QVariant::fromValue<GameConfig>(m_board->gameConfig())
<< static_cast<quint32>(StepQueue::other(m_me));
m_socket->write(gameData);
kDebug() << "Game config sent";
@@ -225,7 +225,7 @@ namespace KDots
QVariant var;
in >> var;
const Point& point = var.value<Point>();
- m_table->pushPoint(point);
+ m_board->pushPoint(point);
}
}
}
diff --git a/plugins/ipconnect/rival.hpp b/plugins/ipconnect/rival.hpp
index 2bedb03..90f3663 100644
--- a/plugins/ipconnect/rival.hpp
+++ b/plugins/ipconnect/rival.hpp
@@ -41,7 +41,7 @@ namespace KDots
{
Q_OBJECT
- std::shared_ptr<BoardModel> m_table;
+ BoardModel *m_board;
QTcpSocket *m_socket;
QTcpServer *m_server;
@@ -56,7 +56,7 @@ namespace KDots
IConfigurationWidget* configureWidget();
- void setBoardModel(std::shared_ptr<BoardModel>& table);
+ void setBoardModel(BoardModel *board);
bool isAllow() const;
diff --git a/plugins/simpleai/plugin.hpp b/plugins/simpleai/plugin.hpp
index 7f68bdf..205d9fe 100644
--- a/plugins/simpleai/plugin.hpp
+++ b/plugins/simpleai/plugin.hpp
@@ -42,9 +42,9 @@ namespace KDots
{
}
- std::shared_ptr<IRival> createRival()
+ std::unique_ptr<IRival> createRival()
{
- return std::shared_ptr<IRival>(new Rival);
+ return std::unique_ptr<IRival>(new Rival);
}
QString name() const
diff --git a/plugins/simpleai/rival.cpp b/plugins/simpleai/rival.cpp
index f96a416..372657b 100644
--- a/plugins/simpleai/rival.cpp
+++ b/plugins/simpleai/rival.cpp
@@ -46,7 +46,7 @@ namespace KDots
{
Rival::Rival(QObject *parent)
: IRival(parent)
- , m_table(NULL)
+ , m_board(NULL)
, m_current(Owner::FIRST)
, m_other(Owner::SECOND)
, m_iterations(1)
@@ -57,10 +57,10 @@ namespace KDots
bool Rival::isAllow() const
{
- if(!m_table)
+ if(!m_board)
return false;
- return m_table->stepQueue().getCurrentOwner() == \
m_table->stepQueue().firstOwner(); + return \
m_board->stepQueue().getCurrentOwner() == m_board->stepQueue().firstOwner(); }
bool Rival::hasMask(const Graph& graph, const Point& point, const MapData& mask, \
const Owner current) @@ -119,7 +119,7 @@ namespace KDots
float Rival::calcPriority(const Point& point)
{
float priority = 2;
- const Graph& graph = m_table->graph();
+ const Graph& graph = m_board->graph();
if(m_iterations > 1 && hasCaptured(point, m_current))
return 1.0;
@@ -162,27 +162,9 @@ namespace KDots
return priority > 1.5 ? 0 : priority;
}
- namespace
- {
- bool isEmptyAround(const Graph& graph, const Point& point)
- {
- for(int i = 0; i < DIRECTION_COUNT; ++i)
- {
- const Point newPoint(point.m_x + GRAPH_DX[i], point.m_y + GRAPH_DY[i]);
- if(!graph.isValid(newPoint))
- continue;
-
- if(graph[newPoint].owner() != Owner::NONE)
- return false;
- }
-
- return true;
- }
- }
-
void Rival::calcRange(int& min_x, int& min_y, int& max_x, int& max_y)
{
- const Graph& graph = m_table->graph();
+ const Graph& graph = m_board->graph();
for(int j = 0, max_j = graph.height(), max_i = graph.width(), i; j < max_j; \
++j) {
for(i = 0; i < max_i; ++i)
@@ -204,10 +186,27 @@ namespace KDots
}
}
+ void Rival::setDifficulty(const KgDifficultyLevel *level)
+ {
+ switch (level->standardLevel())
+ {
+ case KgDifficultyLevel::Easy:
+ m_iterations = 1;
+ break;
+ case KgDifficultyLevel::Medium:
+ m_iterations = 2;
+ break;
+ default:
+ m_iterations = 3;
+ break;
+ }
+ }
+
+
bool Rival::hasCaptured(const KDots::Point& point, KDots::Owner current) const
{
- const Graph& graph = m_table->graph();
- auto steps = m_table->stepQueue();
+ const Graph& graph = m_board->graph();
+ auto steps = m_board->stepQueue();
PolygonFinder findPolygon(graph, current);
//O(n)
@@ -245,7 +244,7 @@ namespace KDots
calcRange(min_x, min_y, max_x, max_y);
const Point minPoint(min_x, min_y), maxPoint(max_x, max_y);
- const Graph& graph = m_table->graph();
+ const Graph& graph = m_board->graph();
m_points.clear();
@@ -273,15 +272,15 @@ namespace KDots
if(!m_points.empty())
{
std::srand(std::time(NULL));
- m_table->pushPoint(m_points[std::rand() % m_points.size()]);
+ m_board->pushPoint(m_points[std::rand() % m_points.size()]);
}
}
- void Rival::setBoardModel(std::shared_ptr<BoardModel>& table)
+ void Rival::setBoardModel(BoardModel *board)
{
- m_table = table;
+ m_board = board;
- m_other = m_table->stepQueue().getCurrentOwner();
+ m_other = m_board->stepQueue().getCurrentOwner();
m_current = StepQueue::other(m_other);
}
}
diff --git a/plugins/simpleai/rival.hpp b/plugins/simpleai/rival.hpp
index 15083de..0e4b535 100644
--- a/plugins/simpleai/rival.hpp
+++ b/plugins/simpleai/rival.hpp
@@ -41,7 +41,7 @@ namespace KDots
Q_OBJECT
Q_INTERFACES(KDots::IRival)
- std::shared_ptr<BoardModel> m_table;
+ BoardModel *m_board;
Owner m_current, m_other;
int m_iterations;
std::vector<Point> m_points;
@@ -52,16 +52,13 @@ namespace KDots
bool isAllow() const;
static bool hasMask(const Graph& graph, const Point& point, const MapData& \
mask, const Owner current);
- void setDifficulty(int diff)
- {
- m_iterations = diff;
- }
-
std::vector<Point> possibleMoves() const;
+ void setBoardModel(BoardModel *board);
+
public slots:
void nextStep(const Point& point);
- void setBoardModel(std::shared_ptr<BoardModel>& table);
+ void setDifficulty(const KgDifficultyLevel *level);
private:
float calcPriority(const Point& point);
diff --git a/plugins/singlepc/plugin.hpp b/plugins/singlepc/plugin.hpp
index 3e8cc79..2ade441 100644
--- a/plugins/singlepc/plugin.hpp
+++ b/plugins/singlepc/plugin.hpp
@@ -74,9 +74,9 @@ namespace KDots
{
}
- std::shared_ptr<IRival> createRival()
+ std::unique_ptr<IRival> createRival()
{
- return std::shared_ptr<IRival>(new Rival);
+ return std::unique_ptr<IRival>(new Rival);
}
QString name() const
diff --git a/pluginwidgetdelegate.cpp b/pluginwidgetdelegate.cpp
index facf689..40e2dad 100644
--- a/pluginwidgetdelegate.cpp
+++ b/pluginwidgetdelegate.cpp
@@ -38,6 +38,12 @@ namespace KDots
}
+ QSize PluginWidgetDelegate::sizeHint(const QStyleOptionViewItem & option, const \
QModelIndex & index) const + {
+ Q_UNUSED(index);
+ return QSize(option.rect.width(), 50);
+ }
+
void PluginWidgetDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem& option, const QModelIndex&) const
{
@@ -56,10 +62,10 @@ namespace KDots
painter->drawText(textRect, Qt::AlignCenter, pluginName);
IPlugin *plug = PluginLoader::instance().plugin(pluginName);
- if(plug)
+ if (plug)
{
const KIcon& plugIcon = plug->icon();
- if(plugIcon.isNull())
+ if (plugIcon.isNull())
{
const KIcon newIcon("applications-boardgames");
drawIcon(painter, option, newIcon);
@@ -72,7 +78,7 @@ namespace KDots
void PluginWidgetDelegate::drawIcon(QPainter *painter,
const QStyleOptionViewItem& option, const KIcon& icon) const
{
- const int delta =(option.rect.width() - 32) / 2;
+ const int delta = (option.rect.width() - 32) / 2;
const QRect iconRect(option.rect.x() + delta, option.rect.y() + 2, 28, 28);
const QPixmap& pixMap = icon.pixmap(iconRect.size());
painter->drawPixmap(iconRect, pixMap, pixMap.rect());
diff --git a/pluginwidgetdelegate.hpp b/pluginwidgetdelegate.hpp
index 9b9bd6c..9b91ee6 100644
--- a/pluginwidgetdelegate.hpp
+++ b/pluginwidgetdelegate.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_PLUGINWIDGETDELEGATE_HPP
-#define KDOTS_PLUGINWIDGETDELEGATE_HPP
+#pragma once
#include <QItemDelegate>
class KIcon;
@@ -36,20 +35,15 @@ namespace KDots
public:
PluginWidgetDelegate(QObject *parent = 0);
- QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) \
const
- {
- Q_UNUSED(index);
- return QSize(option.rect.width(), 50);
- }
+ QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) \
const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
void paint(QPainter *painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
+
private:
void drawIcon(QPainter *painter, const QStyleOptionViewItem& option, const \
KIcon& icon) const; };
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/point.cpp b/point.cpp
index 6ad22ed..c7b53b7 100644
--- a/point.cpp
+++ b/point.cpp
@@ -107,13 +107,13 @@ namespace KDots
QDataStream& operator<<(QDataStream& out, const KDots::Point& obj)
{
- out <<(quint32) obj.m_x <<(quint32) obj.m_y;
+ out << (quint32) obj.m_x << (quint32) obj.m_y;
return out;
}
QDataStream& operator>>(QDataStream& in, KDots::Point& obj)
{
- in >>(quint32&) obj.m_x >>(quint32&) obj.m_y;
+ in >> (quint32&) obj.m_x >> (quint32&) obj.m_y;
return in;
}
}
\ No newline at end of file
diff --git a/point.hpp b/point.hpp
index 8c8180b..1cec7db 100644
--- a/point.hpp
+++ b/point.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_POINT_HPP
-#define KDOTS_POINT_HPP
+#pragma once
#include <QMetaType>
#include "constants.hpp"
@@ -36,9 +35,6 @@ namespace KDots
class KDOTS_EXPORT Point final
{
public:
- int m_x, m_y;
-
- public:
Point();
Point(int x, int y);
@@ -66,6 +62,9 @@ namespace KDots
explicit operator QPointF() const;
explicit operator QPoint() const;
+
+ public:
+ int m_x, m_y;
};
QDataStream& operator<<(QDataStream& out, const Point& obj);
@@ -73,8 +72,4 @@ namespace KDots
QDataStream& operator>>(QDataStream& in, Point& obj);
}
-Q_DECLARE_METATYPE(KDots::Point);
-
-
-
-#endif
\ No newline at end of file
+Q_DECLARE_METATYPE(KDots::Point);
\ No newline at end of file
diff --git a/polygon.cpp b/polygon.cpp
index 94ba87d..fdf5302 100644
--- a/polygon.cpp
+++ b/polygon.cpp
@@ -45,7 +45,7 @@ namespace
{
int res = 0;
KDots::Point prevPoint = polygon.back();
- for(auto itr = polygon.begin(), itrEnd = polygon.end();
+ for (auto itr = polygon.begin(), itrEnd = polygon.end();
itr != itrEnd; ++itr)
{
res += (itr->m_x - prevPoint.m_x) * (itr->m_y + prevPoint.m_y);
@@ -58,7 +58,7 @@ namespace
int KDots::Polygon::area() const
{
- if(m_area < 0)
+ if (m_area < 0)
{
m_area = doubleArea(m_points);
}
@@ -94,9 +94,9 @@ void KDots::Polygon::setOwner(Owner own)
KDots::Point KDots::Polygon::getPrevPoint(std::vector<KDots::Point>::const_iterator \
current) const {
const int currentY = current->m_y;
- for(auto prev = current;;)
+ for (auto prev = current;;)
{
- if(prev == m_points.begin())
+ if (prev == m_points.begin())
prev = --m_points.end();
else
--prev;
@@ -110,15 +110,15 @@ KDots::Point KDots::Polygon::getNextPoint(int& shift, \
std::vector<KDots::Point>: {
const int currentY = current->m_y;
shift = 0;
- for(auto next = current;;)
+ for (auto next = current;;)
{
++shift;
- if(next == --m_points.end())
+ if (next == --m_points.end())
next = m_points.begin();
else
++next;
- if(next->m_y != currentY)
+ if (next->m_y != currentY)
return *next;
}
}
@@ -130,23 +130,21 @@ bool KDots::Polygon::contains(const Point& point) const
int i = 0, shift;
std::vector<KDots::Point>::const_iterator itr = m_points.begin(), itrEnd = \
m_points.end();
- while(itr != itrEnd)
+ while (itr != itrEnd)
{
- if(itr->m_y != point.m_y)
+ if (itr->m_y != point.m_y)
{
++itr;
continue;
}
- if(itr->m_x == point.m_x
-
- )
+ if (itr->m_x == point.m_x)
return true;
const Point& prevPoint = getPrevPoint(itr);
const Point& nextPoint = getNextPoint(shift, itr);
- if(itr->m_x < point.m_x && prevPoint.m_y != nextPoint.m_y && shift == 1)
+ if (itr->m_x < point.m_x && prevPoint.m_y != nextPoint.m_y && shift == 1)
++i;
++itr;
diff --git a/polygon.hpp b/polygon.hpp
index 4e7b8c6..7bf246a 100644
--- a/polygon.hpp
+++ b/polygon.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_POLYGON_HPP
-#define KDOTS_POLYGON_HPP
+#pragma once
#include <list>
#include <vector>
#include <memory>
@@ -35,11 +34,6 @@ namespace KDots
{
class KDOTS_EXPORT Polygon final
{
- std::vector<Point> m_points;
- bool m_filled;
- Owner m_owner;
-
- mutable int m_area;
public:
Polygon();
@@ -62,10 +56,15 @@ namespace KDots
private:
KDots::Point getPrevPoint(std::vector<KDots::Point>::const_iterator current) \
const;
KDots::Point getNextPoint(int& shift, std::vector<KDots::Point>::const_iterator \
current) const; +
+ private:
+ std::vector<Point> m_points;
+ bool m_filled;
+ Owner m_owner;
+
+ mutable int m_area;
};
typedef std::shared_ptr<Polygon> Polygon_ptr;
typedef std::vector<Polygon_ptr> PolyList;
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/polygonfinder.cpp b/polygonfinder.cpp
index 6c216f8..5bada87 100644
--- a/polygonfinder.cpp
+++ b/polygonfinder.cpp
@@ -69,29 +69,28 @@ namespace KDots
void PolygonFinder::findPolygons(const Point& point)
{
- if(m_cache.size() > 3 && point == m_cache.front())
+ if (m_cache.size() > 3 && point == m_cache.front())
{
m_polygons.push_back(Polygon_ptr(new Polygon(m_cache)));
return;
}
- if(m_stepMap[point.m_x][point.m_y])
+ if (m_stepMap[point.m_x][point.m_y])
return;
m_cache.push_back(point);
m_stepMap[point.m_x][point.m_y] = true;
- for(int i = 0; i < DIRECTION_COUNT; ++i)
- {
+ for (int i = 0; i < DIRECTION_COUNT; ++i)
+ {
const Point newPoint(point.m_x + GRAPH_DX[i], point.m_y + GRAPH_DY[i]);
- if(!m_graph.isValid(newPoint))
+ if (!m_graph.isValid(newPoint))
continue;
const GraphPoint& graphPoint = m_graph[newPoint];
- if(newPoint != m_first
- &&(graphPoint.isCaptured() || graphPoint.owner() != m_current))
+ if (newPoint != m_first &&(graphPoint.isCaptured() || graphPoint.owner() != \
m_current)) continue;
findPolygons(newPoint);
diff --git a/polygonfinder.hpp b/polygonfinder.hpp
index 12fe354..2ee9666 100644
--- a/polygonfinder.hpp
+++ b/polygonfinder.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_POLYGONFINDER_HPP
-#define KDOTS_POLYGONFINDER_HPP
+#pragma once
#include <memory>
#include <list>
#include "polygon.hpp"
@@ -36,20 +35,20 @@ namespace KDots
class KDOTS_EXPORT PolygonFinder final
{
- const Graph& m_graph;
- Owner m_current;
- std::vector<Point> m_cache;
- std::vector<std::vector<bool>> m_stepMap;
- PolyList m_polygons;
- Point m_first;
public:
PolygonFinder(const Graph& graph, Owner owner);
// O(n)
const PolyList& operator()(const Point& point);
+
private:
void findPolygons(const Point& point);
+
+ private:
+ const Graph& m_graph;
+ Owner m_current;
+ std::vector<Point> m_cache;
+ std::vector<std::vector<bool>> m_stepMap;
+ PolyList m_polygons;
+ Point m_first;
};
-
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/stepqueue.cpp b/stepqueue.cpp
index 0b806e6..1e74334 100644
--- a/stepqueue.cpp
+++ b/stepqueue.cpp
@@ -28,19 +28,39 @@
namespace KDots
{
StepQueue::StepQueue(Owner firstPlayer)
- : m_firstOwner(firstPlayer)
+ : m_owner(firstPlayer)
+ , m_captured(false)
+ , m_firstOwner(firstPlayer)
, m_first(0)
, m_second(0)
, m_emptyCaptured(0)
- , m_owner(firstPlayer)
- , m_captured(false)
{
}
+
+ Owner StepQueue::firstOwner() const
+ {
+ return m_firstOwner;
+ }
+
+ Point StepQueue::lastPoint() const
+ {
+ return m_points.empty() ? Point() : m_points.back();
+ }
+
+ void StepQueue::clear()
+ {
+ m_first = m_second = m_emptyCaptured = 0;
+ m_owner = m_firstOwner;
+ m_captured = false;
+ m_firstPoints.clear();
+ m_secondPoints.clear();
+ m_points.clear();
+ }
void StepQueue::addPoint(const Point& point)
{
m_points.push_back(point);
- if(getCurrentOwner() == Owner::FIRST)
+ if (getCurrentOwner() == Owner::FIRST)
m_firstPoints.push_back(point);
else
m_secondPoints.push_back(point);
@@ -50,15 +70,68 @@ namespace KDots
{
m_captured = true;
- if(getCurrentOwner() == Owner::FIRST)
+ if (getCurrentOwner() == Owner::FIRST)
++m_first;
else
++m_second;
}
+
+ void StepQueue::addEmptyCaptured()
+ {
+ ++m_emptyCaptured;
+ }
+
+ std::size_t StepQueue::emtyCapturedCount() const
+ {
+ return m_emptyCaptured;
+ }
+
+ Owner StepQueue::getCurrentOwner() const
+ {
+ return m_owner;
+ }
+
+ std::size_t StepQueue::getMarks(Owner owner) const
+ {
+ return owner == Owner::FIRST ? m_first : m_second;
+ }
+
+ const std::vector<Point>& StepQueue::getPoints(Owner owner) const
+ {
+ return owner == Owner::SECOND ? m_secondPoints : m_firstPoints;
+ }
+
+ const std::vector<Point>& StepQueue::getAllPoints() const
+ {
+ return m_points;
+ }
+
+ Owner StepQueue::other(Owner player)
+ {
+ if (player == Owner::NONE)
+ kWarning() << "player == NONE";
+ return player == Owner::FIRST ? Owner::SECOND : Owner::FIRST;
+ }
+
+ Owner StepQueue::nextStep()
+ {
+ m_captured = false;
+ return (m_owner = other(m_owner));
+ }
+
ExtraStepQueue::ExtraStepQueue(Owner firstPlayer)
: StepQueue(firstPlayer)
{
}
+
+ Owner ExtraStepQueue::nextStep()
+ {
+ if (m_captured)
+ return m_owner;
+ m_captured = false;
+
+ return (m_owner = other(m_owner));
+ }
}
\ No newline at end of file
diff --git a/stepqueue.hpp b/stepqueue.hpp
index 5671258..db3a13c 100644
--- a/stepqueue.hpp
+++ b/stepqueue.hpp
@@ -23,8 +23,7 @@
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KDOTS_STEPQUEUE_HPP
-#define KDOTS_STEPQUEUE_HPP
+#pragma once
#include <KDebug>
#include "point.hpp"
#include "constants.hpp"
@@ -33,81 +32,38 @@ namespace KDots
{
class KDOTS_EXPORT StepQueue
{
- Owner m_firstOwner;
- std::vector<Point> m_firstPoints, m_secondPoints, m_points;
- std::size_t m_first, m_second, m_emptyCaptured;
- protected:
- Owner m_owner;
- bool m_captured;
public:
StepQueue(Owner firstPlayer);
virtual ~StepQueue() {}
- Owner firstOwner() const
- {
- return m_firstOwner;
- }
+ Owner firstOwner() const;
+ Point lastPoint() const;
- Point lastPoint() const
- {
- return m_points.empty() ? Point() : m_points.back();
- }
-
- void clear()
- {
- m_first = m_second = m_emptyCaptured = 0;
- m_owner = m_firstOwner;
- m_captured = false;
- m_firstPoints.clear();
- m_secondPoints.clear();
- m_points.clear();
- }
+ void clear();
void addPoint(const Point& point);
void addCaptured();
+ void addEmptyCaptured();
- void addEmptyCaptured()
- {
- ++m_emptyCaptured;
- }
-
- std::size_t emtyCapturedCount() const
- {
- return m_emptyCaptured;
- }
+ std::size_t emtyCapturedCount() const;
- Owner getCurrentOwner() const
- {
- return m_owner;
- }
+ Owner getCurrentOwner() const;
+ std::size_t getMarks(Owner owner) const;
+ const std::vector<Point>& getPoints(Owner owner) const;
+ const std::vector<Point>& getAllPoints() const;
- std::size_t getMarks(Owner owner) const
- {
- return owner == Owner::FIRST ? m_first : m_second;
- }
+ static Owner other(Owner player);
- const std::vector<Point>& getPoints(Owner owner) const
- {
- return owner == Owner::SECOND ? m_secondPoints : m_firstPoints;
- }
+ Owner nextStep();
+
+ protected:
+ Owner m_owner;
+ bool m_captured;
- const std::vector<Point>& getAllPoints() const
- {
- return m_points;
- }
-
- static Owner other(Owner player)
- {
- if(player == Owner::NONE)
- kWarning() << "player == NONE";
- return player == Owner::FIRST ? Owner::SECOND : Owner::FIRST;
- }
-
- Owner nextStep()
- {
- m_captured = false;
- return(m_owner = other(m_owner));
- }
+ private:
+ Owner m_firstOwner;
+ std::vector<Point> m_firstPoints, m_secondPoints, m_points;
+ std::size_t m_first, m_second, m_emptyCaptured;
};
class KDOTS_EXPORT ExtraStepQueue final : public StepQueue
@@ -115,18 +71,8 @@ namespace KDots
public:
ExtraStepQueue(Owner firstPlayer);
- Owner nextStep()
- {
- if(m_captured)
- return m_owner;
-
- m_captured = false;
-
- return(m_owner = other(m_owner));
- }
+ Owner nextStep();
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic