diff --git a/dottable.cpp b/dottable.cpp index 0f833f6..0c17796 100644 --- a/dottable.cpp +++ b/dottable.cpp @@ -24,6 +24,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "dottable.hpp" +#include +#include +#include #include "polygonfinder.hpp" #include "stepqueue.hpp" @@ -125,17 +128,17 @@ namespace KDots //O(n) const PolyList& polyList = findPolygon (point); - const std::list& points = m_steps->getPoints (StepQueue::other (current)); + const auto& points = m_steps->getPoints (StepQueue::other (current)); if (points.empty () || polyList.empty ()) { - m_steps->nextStep (); + continueStep (); emit nextPlayer (point); return; } const Owner otherOwner = StepQueue::other (current); - const std::list& otherOwnerPoints = m_steps->getPoints (otherOwner); + const auto& otherOwnerPoints = m_steps->getPoints (otherOwner); for (const Point& p : otherOwnerPoints) { GraphPoint& gpoint = graph[p]; @@ -177,16 +180,36 @@ namespace KDots } drawPolygon (polyList); - m_steps->nextStep (); + + continueStep (); emit nextPlayer (point); } + + void DotTable::continueStep () + { + const auto& allPoints = m_steps->getAllPoints (); + if (allPoints.size () == m_graph->width () * m_graph->height ()) + { + const int first = m_steps->getMarks (FIRST); + const int second = m_steps->getMarks (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!")); + } + + m_steps->nextStep (); + } //Hardcore undo process void DotTable::undo () { m_graph.reset (new Graph (m_config.m_width, m_config.m_height)); m_polygons.clear (); - std::list points (m_steps->getAllPoints ()); + auto points (m_steps->getAllPoints ()); if (!points.empty ()) points.pop_back (); diff --git a/include/dottable.hpp b/include/dottable.hpp index 018b070..c2df7a2 100644 --- a/include/dottable.hpp +++ b/include/dottable.hpp @@ -69,6 +69,8 @@ namespace KDots void nextPlayer (const Point& lastPoint); private: void drawPolygon (PolyList polygons); + + void continueStep (); }; } diff --git a/include/graph.hpp b/include/graph.hpp index b685f4d..9e10988 100644 --- a/include/graph.hpp +++ b/include/graph.hpp @@ -37,7 +37,7 @@ namespace KDots class graph_iterator : public std::iterator { Graph *m_graph; - int m_x, m_y; + std::size_t m_x, m_y; public: Point point () const @@ -52,14 +52,14 @@ namespace KDots { } - graph_iterator (Graph *graph, int x = 0, int y = 0) + graph_iterator (Graph *graph, std::size_t x = 0, std::size_t y = 0) : m_graph (graph) , m_x (x) , m_y (y) { } - graph_iterator (const Graph *graph, int x = 0, int y = 0) + graph_iterator (const Graph *graph, std::size_t x = 0, std::size_t y = 0) : m_graph (const_cast (graph)) , m_x (x) , m_y (y) @@ -120,12 +120,12 @@ namespace KDots iterator end (); const_iterator end () const; - inline int width () const + inline std::size_t width () const { return m_graph.size (); } - inline int height () const + inline std::size_t height () const { return m_graph.front ().size (); } diff --git a/include/stepqueue.hpp b/include/stepqueue.hpp index f9d2eff..d6ff173 100644 --- a/include/stepqueue.hpp +++ b/include/stepqueue.hpp @@ -25,7 +25,6 @@ */ #ifndef KDOTS_STEPQUEUE_HPP #define KDOTS_STEPQUEUE_HPP -#include #include "point.hpp" #include "constants.hpp" @@ -34,7 +33,7 @@ namespace KDots class KDOTS_EXPORT StepQueue { Owner m_firstOwner; - std::list m_firstPoints, m_secondPoints, m_points; + std::vector m_firstPoints, m_secondPoints, m_points; int m_first, m_second; protected: Owner m_owner; @@ -76,12 +75,12 @@ namespace KDots return owner == FIRST ? m_first : m_second; } - inline std::list getPoints (Owner owner) const + inline std::vector getPoints (Owner owner) const { return owner == SECOND ? m_secondPoints : m_firstPoints; } - inline std::list getAllPoints () const + inline std::vector getAllPoints () const { return m_points; } diff --git a/kdotsui.rc b/kdotsui.rc index 9364e75..dc1400a 100644 --- a/kdotsui.rc +++ b/kdotsui.rc @@ -11,6 +11,8 @@ File + + Game diff --git a/mainwindow.cpp b/mainwindow.cpp index b44f513..9a0c9c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -137,13 +137,18 @@ namespace KDots 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); - actionCollection ()->addAction ("UndoGame", undoAction); + //actionCollection ()->addAction ("UndoGame", undoAction); connect (this, SIGNAL (endActionEnable (bool)), diff --git a/plugins/simpleai/rival.cpp b/plugins/simpleai/rival.cpp index 2a1ebda..6d43a03 100644 --- a/plugins/simpleai/rival.cpp +++ b/plugins/simpleai/rival.cpp @@ -97,8 +97,9 @@ namespace KDots const int dy = currentPoint.y () - j; const int newX = point.x () + dx; const int newY = point.y () + dy; - if (newX < 0 || newY < 0 || newX >= graph.width () - || newY >= graph.height ()) + if (newX < 0 || newY < 0 + || static_cast (newX) >= graph.width () + || static_cast (newY) >= graph.height ()) goto endloop; const MapElement el = map[j][i]; @@ -147,7 +148,8 @@ namespace KDots { const Point newPoint (point.x () + GRAPH_DX[i], point.y () + GRAPH_DY[i]); if (newPoint.x () < 0 || newPoint.y () < 0 - || newPoint.x () >= graph.width () || newPoint.y () >= graph.height ()) + || static_cast (newPoint.x ()) >= graph.width () + || static_cast (newPoint.y ()) >= graph.height ()) continue; if (graph[newPoint].owner () != NONE) @@ -242,7 +244,9 @@ namespace KDots const int tempx = point.x () + GRAPH_DX[i]; const int tempy = point.y () + GRAPH_DY[i]; - if (tempx < 0 || tempy < 0 || tempx >= gr.width () || tempy >= gr.height ()) + if (tempx < 0 || tempy < 0 + || static_cast (tempx) >= gr.width () + || static_cast (tempy) >= gr.height ()) continue; const Point newPoint (tempx, tempy); @@ -273,6 +277,7 @@ namespace KDots void Rival::setStatusBar (QStatusBar* bar) { + Q_UNUSED (bar); } } diff --git a/polygonfinder.cpp b/polygonfinder.cpp index 8eb302d..4798d41 100644 --- a/polygonfinder.cpp +++ b/polygonfinder.cpp @@ -112,7 +112,9 @@ namespace KDots const int tempx = point.x () + GRAPH_DX[i]; const int tempy = point.y () + GRAPH_DY[i]; - if (tempx < 0 || tempy < 0 || tempx >= m_graph.width () || tempy >= m_graph.height ()) + if (tempx < 0 || tempy < 0 + || static_cast (tempx) >= m_graph.width () + || static_cast (tempy) >= m_graph.height ()) continue; findPolygons (Point (tempx, tempy)); diff --git a/tablewidget.cpp b/tablewidget.cpp index 8d33f8d..2f63153 100644 --- a/tablewidget.cpp +++ b/tablewidget.cpp @@ -131,7 +131,6 @@ namespace KDots const float tableHeight = cellSize * m_height; QPixmap pixmap (QSize (tableWidth, tableHeight)); - pixmap.fill (Qt::white); QPainter pixPainter (&pixmap); @@ -143,7 +142,10 @@ namespace KDots 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)); + pixPainter.drawRect (0, 0, pixmap.width (), pixmap.height ()); + const Graph& graph = m_table->graph (); const Point& lastPoint = m_table->stepQueue ()->lastPoint ();