[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdots] /: A bit refactoring. Renaming DotTable to BoardModel.
From: Minh Ngo <nlminhtl () gmail ! com>
Date: 2014-12-31 17:32:54
Message-ID: E1Y6N8g-0005pl-9J () scm ! kde ! org
[Download RAW message or body]
Git commit 36e72f59a7e5e3158c3d5fbcfe19d8a3b940a1b2 by Minh Ngo.
Committed on 30/12/2014 at 21:03.
Pushed by minhngo into branch 'master'.
A bit refactoring. Renaming DotTable to BoardModel.
M +2 -2 CMakeLists.txt
R +44 -34 boardmodel.cpp [from: dottable.cpp - 067% similarity]
R +12 -12 boardmodel.hpp [from: dottable.hpp - 090% similarity]
M +3 -3 interface/irival.hpp
M +3 -3 mainwindow.cpp
M +2 -2 plugins/ipconnect/rival.cpp
M +4 -4 plugins/ipconnect/rival.hpp
M +2 -2 plugins/simpleai/rival.cpp
M +3 -3 plugins/simpleai/rival.hpp
M +1 -1 plugins/singlepc/plugin.hpp
M +2 -2 tablewidget.cpp
M +3 -3 tablewidget.hpp
http://commits.kde.org/kdots/36e72f59a7e5e3158c3d5fbcfe19d8a3b940a1b2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 195b2ab..bfe87f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,7 +49,7 @@ ENDIF(UNIX)
SET(KDOTSLIB_SRCS
point.cpp
graph.cpp
- dottable.cpp
+ boardmodel.cpp
stepqueue.cpp
polygon.cpp
polygonfinder.cpp
@@ -59,7 +59,7 @@ SET(KDOTSLIB_SRCS
SET(KDOTSLIB_HEADERS
graphpoint.hpp
graph.hpp
- dottable.hpp
+ boardmodel.hpp
stepqueue.hpp
edgelist.hpp
point.hpp
diff --git a/dottable.cpp b/boardmodel.cpp
similarity index 67%
rename from dottable.cpp
rename to boardmodel.cpp
index 2d0ae70..985fc75 100644
--- a/dottable.cpp
+++ b/boardmodel.cpp
@@ -23,7 +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.
*/
-#include "dottable.hpp"
+#include "boardmodel.hpp"
#include <KMessageBox>
#include <KLocalizedString>
#include <KDebug>
@@ -33,7 +33,7 @@
namespace KDots
{
- DotTable::DotTable(const GameConfig& config, std::shared_ptr<StepQueue> \
step_queue, QObject *parent) + BoardModel::BoardModel(const GameConfig& config, \
std::shared_ptr<StepQueue> step_queue, QObject *parent) : QObject(parent)
, m_graph(new Graph(config.m_width, config.m_height))
, m_steps(step_queue)
@@ -41,17 +41,17 @@ namespace KDots
{
}
- const GameConfig& DotTable::gameConfig() const
+ const GameConfig& BoardModel::gameConfig() const
{
return m_config;
}
- void DotTable::pushPoint(const Point& point)
+ void BoardModel::pushPoint(const Point& point)
{
Graph& graph = *m_graph;
GraphPoint& currentPoint = graph[point];
- if(currentPoint.owner() != Owner::NONE || currentPoint.isCaptured())
+ if (currentPoint.owner() != Owner::NONE || currentPoint.isCaptured())
return;
const Owner current = m_steps->getCurrentOwner();
@@ -66,7 +66,7 @@ namespace KDots
const PolyList& polyList = findPolygon(point);
const auto& points = m_steps->getPoints(StepQueue::other(current));
- if(points.empty() || polyList.empty())
+ if (points.empty() || polyList.empty())
{
continueStep();
emit nextPlayer(point);
@@ -76,17 +76,17 @@ namespace KDots
const Owner otherOwner = StepQueue::other(current);
const auto& otherOwnerPoints = m_steps->getPoints(otherOwner);
- for(const Point& p : otherOwnerPoints)
+ for (const Point& p : otherOwnerPoints)
{
GraphPoint& gpoint = graph[p];
- if(gpoint.isCaptured())
+ if (gpoint.isCaptured())
continue;
- for(const Polygon_ptr& polygon : polyList)
+ for (const Polygon_ptr& polygon : polyList)
{
- if(polygon->contains(p))
+ if (polygon->contains(p))
{
- if(gpoint.owner() == otherOwner)
+ if (gpoint.owner() == otherOwner)
{
polygon->setFilled(true);
m_steps->addCaptured();
@@ -98,17 +98,17 @@ namespace KDots
}
}
- for(Graph::iterator itr = graph.begin(), itrEnd = graph.end();
+ for (Graph::iterator itr = graph.begin(), itrEnd = graph.end();
itr != itrEnd; ++itr)
{
- if(itr->isCaptured() || itr->owner() != Owner::NONE)
+ if (itr->isCaptured() || itr->owner() != Owner::NONE)
continue;
- for(const Polygon_ptr& polygon : polyList)
+ for (const Polygon_ptr& polygon : polyList)
{
const Point& newPoint = itr.point();
- if(polygon->contains(newPoint) && polygon->isFilled())
+ if (polygon->contains(newPoint) && polygon->isFilled())
{
itr->capture();
m_steps->addEmptyCaptured();
@@ -123,45 +123,55 @@ namespace KDots
emit nextPlayer(point);
}
- void DotTable::continueStep()
+ namespace
+ {
+ QString getResult(int firstPoints, int secondPoints)
+ {
+ if (firstPoints > secondPoints)
+ return i18n("The first player win!");
+
+ if (firstPoints < secondPoints)
+ return i18n("The second player win!");
+
+ return i18n("Dead heat!");
+ }
+ }
+
+ void BoardModel::continueStep()
{
const auto& allPoints = m_steps->getAllPoints();
- if(allPoints.size() + m_steps->emtyCapturedCount() == m_graph->width() * \
m_graph->height()) + if (allPoints.size() + m_steps->emtyCapturedCount() == \
m_graph->width() * m_graph->height()) {
const int first = m_steps->getMarks(Owner::FIRST);
const int second = m_steps->getMarks(Owner::SECOND);
- if(first > second)
- KMessageBox::information(0, i18n("The first player win!"), i18n("The first \
player win!"));
- else if(first < second)
- KMessageBox::information(0, i18n("The second player win!"), i18n("The second \
player win!"));
- else
- KMessageBox::information(0, i18n("Dead heat!"), i18n("Dead heat!"));
+ const QString& message = getResult(first, second);
+ KMessageBox::information(0, message, message);
}
m_steps->nextStep();
}
//Hardcore undo process
- void DotTable::undo()
+ void BoardModel::undo()
{
m_graph.reset(new Graph(m_config.m_width, m_config.m_height));
m_polygons.clear();
auto points(m_steps->getAllPoints());
- if(!points.empty())
+ if (!points.empty())
points.pop_back();
m_steps->clear();
- for(const Point& point : points)
+ for (const Point& point : points)
pushPoint(point);
}
- void DotTable::drawPolygon(PolyList polygons)
+ void BoardModel::drawPolygon(PolyList polygons)
{
- for(Polygon_ptr& polygon : polygons)
+ for (Polygon_ptr& polygon : polygons)
{
- if(!polygon->isFilled())
+ if (!polygon->isFilled())
continue;
polygon->setOwner(m_steps->getCurrentOwner());
@@ -169,7 +179,7 @@ namespace KDots
Point prevPoint = polygon->points().back();
- for(const Point& currPoint : polygon->points())
+ for (const Point& currPoint : polygon->points())
{
m_graph->addEdge(prevPoint, currPoint);
prevPoint = currPoint;
@@ -177,20 +187,20 @@ namespace KDots
}
}
- const std::vector<Polygon_ptr>& DotTable::polygons() const
+ const std::vector<Polygon_ptr>& BoardModel::polygons() const
{
return m_polygons;
}
- const Graph& DotTable::graph() const
+ const Graph& BoardModel::graph() const
{
return *m_graph;
}
- const StepQueue& DotTable::stepQueue() const
+ const StepQueue& BoardModel::stepQueue() const
{
return *m_steps;
}
}
-#include "dottable.moc"
+#include "boardmodel.moc"
diff --git a/dottable.hpp b/boardmodel.hpp
similarity index 90%
rename from dottable.hpp
rename to boardmodel.hpp
index 0c83cd1..d063503 100644
--- a/dottable.hpp
+++ b/boardmodel.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_DOTTABLE_HPP
-#define KDOTS_DOTTABLE_HPP
+#pragma once
#include <memory>
#include <QObject>
#include "gameconfig.hpp"
@@ -34,16 +33,11 @@ namespace KDots
{
class Graph;
class StepQueue;
- class KDOTS_EXPORT DotTable : public QObject
+ class KDOTS_EXPORT BoardModel : public QObject
{
Q_OBJECT
-
- std::unique_ptr<Graph> m_graph;
- std::shared_ptr<StepQueue> m_steps;
- GameConfig m_config;
- std::vector<Polygon_ptr> m_polygons;
public:
- DotTable(const GameConfig& config, std::shared_ptr<StepQueue> step_queue, \
QObject *parent = 0); + BoardModel(const GameConfig& config, \
std::shared_ptr<StepQueue> step_queue, QObject *parent = 0);
const GameConfig& gameConfig() const;
@@ -56,13 +50,19 @@ namespace KDots
const StepQueue& stepQueue() const;
void undo();
+
signals:
void nextPlayer(const Point& lastPoint);
+
private:
void drawPolygon(PolyList polygons);
void continueStep();
+
+ private:
+ std::unique_ptr<Graph> m_graph;
+ std::shared_ptr<StepQueue> m_steps;
+ GameConfig m_config;
+ std::vector<Polygon_ptr> m_polygons;
};
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/interface/irival.hpp b/interface/irival.hpp
index fb12180..e09627a 100644
--- a/interface/irival.hpp
+++ b/interface/irival.hpp
@@ -34,7 +34,7 @@ class QStatusBar;
namespace KDots
{
- class DotTable;
+ class BoardModel;
class IConfigurationWidget;
class IRival : public QObject
@@ -72,7 +72,7 @@ namespace KDots
Q_UNUSED(point);
}
- virtual void setDotTable(std::shared_ptr<DotTable>& table)
+ virtual void setBoardModel(std::shared_ptr<BoardModel>& table)
{
Q_UNUSED(table);
}
@@ -93,7 +93,7 @@ namespace KDots
}
protected: //signals
- virtual void createDotTable(const GameConfig& config) = 0;
+ virtual void createBoardModel(const GameConfig& config) = 0;
virtual void needDestroy() = 0;
};
diff --git a/mainwindow.cpp b/mainwindow.cpp
index cf3983f..532e24c 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -42,7 +42,7 @@
#include "kdots.h"
#include "stepqueue.hpp"
#include "graph.hpp"
-#include "dottable.hpp"
+#include "boardmodel.hpp"
namespace KDots
@@ -188,9 +188,9 @@ namespace KDots
m_table = new TableWidget(config, this);
- auto model = std::make_shared<DotTable>(config, createStepQueue(config));
+ auto model = std::make_shared<BoardModel>(config, createStepQueue(config));
- m_rival->setDotTable(model);
+ m_rival->setBoardModel(model);
connect(model.get(), SIGNAL(nextPlayer(const Point&)), m_rival.get(), \
SLOT(nextStep(const Point&)));
diff --git a/plugins/ipconnect/rival.cpp b/plugins/ipconnect/rival.cpp
index 3ec2d76..2928289 100644
--- a/plugins/ipconnect/rival.cpp
+++ b/plugins/ipconnect/rival.cpp
@@ -28,7 +28,7 @@
#include <KDebug>
#include <KLocalizedString>
#include <KgDifficulty>
-#include <dottable.hpp>
+#include <boardmodel.hpp>
#include <stepqueue.hpp>
#include <graph.hpp>
#include "connectdialog.hpp"
@@ -144,7 +144,7 @@ namespace KDots
return GameConfig();
}
- void Rival::setDotTable(std::shared_ptr<DotTable>& table) //Is called after \
configureWidget + void Rival::setBoardModel(std::shared_ptr<BoardModel>& table) \
//Is called after configureWidget {
m_table = table;
diff --git a/plugins/ipconnect/rival.hpp b/plugins/ipconnect/rival.hpp
index c8f18fe..2bedb03 100644
--- a/plugins/ipconnect/rival.hpp
+++ b/plugins/ipconnect/rival.hpp
@@ -33,7 +33,7 @@
namespace KDots
{
- class DotTable;
+ class BoardModel;
namespace ipconnect
{
class ConfigurationWidget;
@@ -41,7 +41,7 @@ namespace KDots
{
Q_OBJECT
- std::shared_ptr<DotTable> m_table;
+ std::shared_ptr<BoardModel> m_table;
QTcpSocket *m_socket;
QTcpServer *m_server;
@@ -56,7 +56,7 @@ namespace KDots
IConfigurationWidget* configureWidget();
- void setDotTable(std::shared_ptr<DotTable>& table);
+ void setBoardModel(std::shared_ptr<BoardModel>& table);
bool isAllow() const;
@@ -68,7 +68,7 @@ namespace KDots
void onReadyRead();
void onDisconnected();
signals:
- void createDotTable(const GameConfig& config);
+ void createBoardModel(const GameConfig& config);
void needDestroy();
};
}
diff --git a/plugins/simpleai/rival.cpp b/plugins/simpleai/rival.cpp
index c3f1727..f96a416 100644
--- a/plugins/simpleai/rival.cpp
+++ b/plugins/simpleai/rival.cpp
@@ -33,7 +33,7 @@
#include <KgDifficulty>
#include <KDebug>
#include <point.hpp>
-#include <dottable.hpp>
+#include <boardmodel.hpp>
#include <stepqueue.hpp>
#include <constants.hpp>
#include <polygonfinder.hpp>
@@ -277,7 +277,7 @@ namespace KDots
}
}
- void Rival::setDotTable(std::shared_ptr<DotTable>& table)
+ void Rival::setBoardModel(std::shared_ptr<BoardModel>& table)
{
m_table = table;
diff --git a/plugins/simpleai/rival.hpp b/plugins/simpleai/rival.hpp
index 0f6ab36..15083de 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<DotTable> m_table;
+ std::shared_ptr<BoardModel> m_table;
Owner m_current, m_other;
int m_iterations;
std::vector<Point> m_points;
@@ -61,7 +61,7 @@ namespace KDots
public slots:
void nextStep(const Point& point);
- void setDotTable(std::shared_ptr<DotTable>& table);
+ void setBoardModel(std::shared_ptr<BoardModel>& table);
private:
float calcPriority(const Point& point);
@@ -69,7 +69,7 @@ namespace KDots
bool hasCaptured(const Point& point, Owner current) const;
signals:
- void createDotTable(const GameConfig& config);
+ void createBoardModel(const GameConfig& config);
void needDestroy();
};
}
diff --git a/plugins/singlepc/plugin.hpp b/plugins/singlepc/plugin.hpp
index 7cd111c..3e8cc79 100644
--- a/plugins/singlepc/plugin.hpp
+++ b/plugins/singlepc/plugin.hpp
@@ -60,7 +60,7 @@ namespace KDots
Q_UNUSED(point);
}
signals:
- void createDotTable(const GameConfig& config);
+ void createBoardModel(const GameConfig& config);
void needDestroy();
};
diff --git a/tablewidget.cpp b/tablewidget.cpp
index 8771e68..5f5cad5 100644
--- a/tablewidget.cpp
+++ b/tablewidget.cpp
@@ -32,7 +32,7 @@
#include <QPainter>
#include <interface/iplugin.hpp>
#include <interface/irival.hpp>
-#include "dottable.hpp"
+#include "boardmodel.hpp"
#include "stepqueue.hpp"
#include "brushcombodelegate.hpp"
#include "kdots.h"
@@ -50,7 +50,7 @@ namespace KDots
setMouseTracking(true);
}
- void TableWidget::setModel(std::shared_ptr<DotTable>& table)
+ void TableWidget::setModel(std::shared_ptr<BoardModel>& table)
{
m_table = table;
diff --git a/tablewidget.hpp b/tablewidget.hpp
index 2676ce0..87aec36 100644
--- a/tablewidget.hpp
+++ b/tablewidget.hpp
@@ -35,7 +35,7 @@ class QPainter;
namespace KDots
{
class IRival;
- class DotTable;
+ class BoardModel;
struct GameConfig;
class TableWidget : public QWidget
@@ -44,7 +44,7 @@ namespace KDots
public:
TableWidget(const GameConfig& config, QWidget *parent = 0);
void undo();
- void setModel(std::shared_ptr<DotTable>& table);
+ void setModel(std::shared_ptr<BoardModel>& table);
void setRival(std::shared_ptr<IRival>& rival);
protected:
@@ -66,7 +66,7 @@ namespace KDots
void updateStatusBar(const QString& msg);
private:
- std::shared_ptr<DotTable> m_table;
+ std::shared_ptr<BoardModel> m_table;
std::shared_ptr<IRival> m_rival;
int m_height;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic