Permalink
Browse files

Upd. interface

  • Loading branch information...
1 parent 96621b4 commit 4d7fdc7a1241685ae2513194a2260856f3ab5c3d @Ignotus committed Aug 24, 2012
Showing with 62 additions and 22 deletions.
  1. +28 −5 dottable.cpp
  2. +2 −0 include/dottable.hpp
  3. +5 −5 include/graph.hpp
  4. +3 −4 include/stepqueue.hpp
  5. +2 −0 kdotsui.rc
  6. +6 −1 mainwindow.cpp
  7. +9 −4 plugins/simpleai/rival.cpp
  8. +3 −1 polygonfinder.cpp
  9. +4 −2 tablewidget.cpp
View
@@ -24,6 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dottable.hpp"
+#include <KMessageBox>
+#include <KLocalizedString>
+#include <KDebug>
#include "polygonfinder.hpp"
#include "stepqueue.hpp"
@@ -125,17 +128,17 @@ namespace KDots
//O(n)
const PolyList& polyList = findPolygon (point);
- const std::list<Point>& 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<Point>& 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<Point> points (m_steps->getAllPoints ());
+ auto points (m_steps->getAllPoints ());
if (!points.empty ())
points.pop_back ();
View
@@ -69,6 +69,8 @@ namespace KDots
void nextPlayer (const Point& lastPoint);
private:
void drawPolygon (PolyList polygons);
+
+ void continueStep ();
};
}
View
@@ -37,7 +37,7 @@ namespace KDots
class graph_iterator : public std::iterator<std::forward_iterator_tag, A>
{
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*> (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 ();
}
View
@@ -25,7 +25,6 @@
*/
#ifndef KDOTS_STEPQUEUE_HPP
#define KDOTS_STEPQUEUE_HPP
-#include <list>
#include "point.hpp"
#include "constants.hpp"
@@ -34,7 +33,7 @@ namespace KDots
class KDOTS_EXPORT StepQueue
{
Owner m_firstOwner;
- std::list<Point> m_firstPoints, m_secondPoints, m_points;
+ std::vector<Point> 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<Point> getPoints (Owner owner) const
+ inline std::vector<Point> getPoints (Owner owner) const
{
return owner == SECOND ? m_secondPoints : m_firstPoints;
}
- inline std::list<Point> getAllPoints () const
+ inline std::vector<Point> getAllPoints () const
{
return m_points;
}
View
@@ -11,6 +11,8 @@
<text>File</text>
<Action name="NewGame" />
<Action name="EndGame" />
+ <Separator />
+ <Action name="Quit" />
</Menu>
<Menu noMerge="1" name="Game">
<text>Game</text>
View
@@ -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)),
View
@@ -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<std::size_t> (newX) >= graph.width ()
+ || static_cast<std::size_t> (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<std::size_t> (newPoint.x ()) >= graph.width ()
+ || static_cast<std::size_t> (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<std::size_t> (tempx) >= gr.width ()
+ || static_cast<std::size_t> (tempy) >= gr.height ())
continue;
const Point newPoint (tempx, tempy);
@@ -273,6 +277,7 @@ namespace KDots
void Rival::setStatusBar (QStatusBar* bar)
{
+ Q_UNUSED (bar);
}
}
View
@@ -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<std::size_t> (tempx) >= m_graph.width ()
+ || static_cast<std::size_t> (tempy) >= m_graph.height ())
continue;
findPolygons (Point (tempx, tempy));
View
@@ -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 ();

0 comments on commit 4d7fdc7

Please sign in to comment.