[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdots] /: Redesign plugin interfaces. Refactoring in random parts.
From:       Minh Ngo <nlminhtl () gmail ! com>
Date:       2014-12-31 17:32:56
Message-ID: E1Y6N8i-0005pl-6w () scm ! kde ! org
[Download RAW message or body]

Git commit 033617098c6ad34b23d31240341c13bdf2243cb7 by Minh Ngo.
Committed on 31/12/2014 at 12:21.
Pushed by minhngo into branch 'master'.

Redesign plugin interfaces. Refactoring in random parts.

Making board view depended only on board model conditions. Adding
points to a board is done now via signals.

Plugins can own one of players now. Blocking access is determined
inside BoardModel. Step queue is storing now in unique_ptr.

Function for localizing plugin texts was added.

M  +34   -13   boardmodel.cpp
M  +12   -9    boardmodel.hpp
M  +8    -31   boardview.cpp
M  +4    -7    boardview.hpp
M  +1    -1    interface/iconfigurationwidget.hpp
M  +13   -27   interface/irival.hpp
M  +6    -7    mainwindow.cpp
M  +12   -4    newgamedialog.cpp
M  +3    -1    newgamedialog.hpp
M  +1    -1    pluginmanagerwidget.cpp
M  +33   -0    plugins/simpleai/plugin.cpp
M  +7    -28   plugins/simpleai/plugin.hpp
M  +2    -5    plugins/simpleai/prioritymap.hpp
M  +6    -15   plugins/simpleai/rival.cpp
M  +8    -11   plugins/simpleai/rival.hpp
M  +53   -0    plugins/singlepc/plugin.cpp
M  +15   -50   plugins/singlepc/plugin.hpp

http://commits.kde.org/kdots/033617098c6ad34b23d31240341c13bdf2243cb7

diff --git a/boardmodel.cpp b/boardmodel.cpp
index 400bd5e..a39e07e 100644
--- a/boardmodel.cpp
+++ b/boardmodel.cpp
@@ -35,10 +35,10 @@
 
 namespace KDots
 {
-  BoardModel::BoardModel(const GameConfig& config, std::shared_ptr<StepQueue> \
step_queue, QObject *parent) +  BoardModel::BoardModel(const GameConfig& config, \
std::unique_ptr<StepQueue>&& step_queue, QObject *parent)  : QObject(parent)
     , m_graph(new Graph(config.m_width, config.m_height))
-    , m_steps(step_queue)
+    , m_steps(std::move(step_queue))
     , m_config(config)
   {
   }
@@ -47,27 +47,36 @@ namespace KDots
   {
     m_view = std::move(view);
     m_view->setModel(this);
+    
+    connect(m_view.get(), SIGNAL(pointClicked(const Point&)), this, \
SLOT(addPoint(const Point&)));  }
   
   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;
+    connect(this, SIGNAL(pointAdded(const Point&)), m_rival.get(), \
SLOT(onPointAdded(const Point&))); +    connect(m_rival.get(), \
SIGNAL(needAddPoint(const Point&)), this, SLOT(addPoint(const Point&)));  }
   
   const GameConfig& BoardModel::gameConfig() const
   {
     return m_config;
   }
-
-  void BoardModel::pushPoint(const Point& point)
+  
+  void BoardModel::addPoint(const Point& point)
   {
+    if (sender() == m_rival.get())
+    {
+      if (m_rival->owner() != m_steps->getCurrentOwner())
+        return;
+    }
+    else
+    {
+      if (m_rival->owner() == m_steps->getCurrentOwner())
+        return;
+    }
+    
     Graph& graph = *m_graph;
     GraphPoint& currentPoint = graph[point];
 
@@ -89,7 +98,8 @@ namespace KDots
     if (points.empty() || polyList.empty())
     {
       continueStep();
-      emit nextPlayer(point);
+      emitStatus();
+      emit pointAdded(point);
       return;
     }
     
@@ -140,7 +150,8 @@ namespace KDots
     drawPolygon(polyList);
     
     continueStep();
-    emit nextPlayer(point);
+    emitStatus();
+    emit pointAdded(point);
   }
   
   namespace
@@ -175,6 +186,7 @@ namespace KDots
   //Hardcore undo process
   void BoardModel::undo()
   {
+    emit freezeView(true);
     m_graph.reset(new Graph(m_config.m_width, m_config.m_height));
     m_polygons.clear();
     auto points(m_steps->getAllPoints());
@@ -184,7 +196,16 @@ namespace KDots
     m_steps->clear();
 
     for (const Point& point : points)
-      pushPoint(point);
+      addPoint(point);
+    
+    emit freezeView(false);
+  }
+  
+  void BoardModel::emitStatus()
+  {
+    const QString& firstMark = QString::number(m_steps->getMarks(Owner::FIRST));
+    const QString& secondMark = QString::number(m_steps->getMarks(Owner::SECOND));
+    emit statusUpdated(QString("First:\t%1\tSecond:\t%2").arg(firstMark, \
secondMark));  }
   
   void BoardModel::drawPolygon(PolyList polygons)
diff --git a/boardmodel.hpp b/boardmodel.hpp
index 246ca44..1d7f178 100644
--- a/boardmodel.hpp
+++ b/boardmodel.hpp
@@ -39,14 +39,12 @@ namespace KDots
   {
     Q_OBJECT
   public:
-    BoardModel(const GameConfig& config, std::shared_ptr<StepQueue> step_queue, \
QObject *parent = 0); +    BoardModel(const GameConfig& config, \
std::unique_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);
     
     const std::vector<Polygon_ptr>& polygons() const;
 
@@ -54,17 +52,21 @@ namespace KDots
 
     const StepQueue& stepQueue() const;
     
-    IRival& rival() const;
-    
+  public slots:
     void undo();
 
-  signals:
-    void nextPlayer(const Point& lastPoint);
-
   private:
     void drawPolygon(PolyList polygons);
-    
     void continueStep();
+    void emitStatus();
+    
+  private slots:
+    void addPoint(const Point& point);
+    
+  signals:
+    void pointAdded(const Point& lastPoint);
+    void freezeView(bool);
+    void statusUpdated(const QString& message);
     
   private:
     std::unique_ptr<IBoardView> m_view;
@@ -74,5 +76,6 @@ namespace KDots
     std::shared_ptr<StepQueue> m_steps;
     GameConfig m_config;
     std::vector<Polygon_ptr> m_polygons;
+    bool m_block;
   };
 }
\ No newline at end of file
diff --git a/boardview.cpp b/boardview.cpp
index 7958e32..7a07743 100644
--- a/boardview.cpp
+++ b/boardview.cpp
@@ -54,13 +54,18 @@ namespace KDots
   {
     m_model = model;
     
-    connect(m_model, SIGNAL(nextPlayer(const Point&)), this, SLOT(update()));
-    connect(m_model, SIGNAL(nextPlayer(const Point&)), this, \
SLOT(onStatusMessage())); +    connect(m_model, SIGNAL(pointAdded(const Point&)), \
this, SLOT(update())); +    connect(m_model, SIGNAL(freezeView(bool)), this, \
SLOT(onFreezeView(bool)));  
     m_height = m_model->gameConfig().m_height + 1;
     m_width = m_model->gameConfig().m_width + 1;
   }
   
+  void BoardView::onFreezeView(bool freeze)
+  {
+    setUpdatesEnabled(!freeze);
+  }
+  
   namespace
   {
     float calculateCellSize(const QRect& rectange, int height, int width)
@@ -74,9 +79,6 @@ namespace KDots
   
   void BoardView::calculatePoint(Point& point, QMouseEvent *event)
   {
-    if (!m_model->rival().isAllow())
-      return;
-    
     const QRect& rectange = rect();
 
     const float cellSize = calculateCellSize(rectange, m_height, m_width);
@@ -125,28 +127,13 @@ namespace KDots
       update();
   }
   
-  void BoardView::onStatusMessage()
-  {
-    emit statusUpdated(QString("First:\t")
-        + QString::number(m_model->stepQueue().getMarks(Owner::FIRST))
-        + "\tSecond:\t"
-        + QString::number(m_model->stepQueue().getMarks(Owner::SECOND)));
-  }
-
   void BoardView::mousePressEvent(QMouseEvent *event)
   {
     Point point;
     calculatePoint(point, event);
     
     if (!point.empty())
-      m_model->pushPoint(point);
-  }
-  
-  void BoardView::undo()
-  {
-    setUpdatesEnabled(false);
-    m_model->undo();
-    setUpdatesEnabled(true);
+      emit pointClicked(point);
   }
   
   void BoardView::drawPolygons(QPainter& painter, float cellSize)
@@ -207,16 +194,6 @@ namespace KDots
       const Point& newPoint = lastPoint + 1;
       painter.drawEllipse(QPointF(newPoint) * cellSize, 6, 6);
     }
-    
-    const std::vector<Point>& possiblePoints = m_model->rival().possibleMoves();
-    for (const Point& point : possiblePoints)
-    {
-      painter.setPen(Qt::gray);
-            
-      painter.setBrush(Qt::NoBrush);
-      const Point& newPoint = point + 1;
-      painter.drawEllipse(QPointF(newPoint) * cellSize, 10, 10);
-    }
   }
   
   void BoardView::drawUnderMousePoint(QPainter& painter, float cellSize)
diff --git a/boardview.hpp b/boardview.hpp
index eec9f99..26b1f96 100644
--- a/boardview.hpp
+++ b/boardview.hpp
@@ -46,7 +46,7 @@ namespace KDots
     void setModel(BoardModel *table);
     
   public slots:
-    void undo();
+    void onFreezeView(bool freeze);
 
   protected:
     void mousePressEvent(QMouseEvent *event);
@@ -59,13 +59,10 @@ namespace KDots
     void fillPolygon(QPainter& painter, float cellSize);
     void drawLastPoint(QPainter& painter, float cellSize);
     void drawUnderMousePoint(QPainter& painter, float cellSize);
-
-  private slots:
-    void onStatusMessage();
-
+  
   signals:
-    void statusUpdated(const QString& msg);
-    
+    void pointClicked(const Point& point);
+
   private:
     BoardModel *m_model;
     
diff --git a/interface/iconfigurationwidget.hpp b/interface/iconfigurationwidget.hpp
index fa35f9f..3c780f4 100644
--- a/interface/iconfigurationwidget.hpp
+++ b/interface/iconfigurationwidget.hpp
@@ -38,7 +38,7 @@ namespace KDots
     }
   
   protected:
-    virtual void needCreateTable(bool) = 0;
+    virtual void needCreateBoard(bool) = 0;
   };
 }
 
diff --git a/interface/irival.hpp b/interface/irival.hpp
index e31cbeb..d42ad22 100644
--- a/interface/irival.hpp
+++ b/interface/irival.hpp
@@ -24,10 +24,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #pragma once
-#include <memory>
 #include <QObject>
-#include <newgamewidget.hpp>
-#include <point.hpp>
+#include <constants.hpp>
 
 class QStatusBar;
 class KgDifficultyLevel;
@@ -35,6 +33,8 @@ class KgDifficultyLevel;
 namespace KDots
 {
   class BoardModel;
+  class Point;
+  class GameConfig;
   class IConfigurationWidget;
   
   class IRival : public QObject
@@ -49,27 +49,9 @@ namespace KDots
     {
     }
     
-    virtual std::vector<Point> possibleMoves() const
-    {
-      return std::vector<Point>();
-    }
-
     virtual IConfigurationWidget* configureWidget()
     {
-      return NULL;
-    }
-    
-    virtual bool isAllow() const = 0;
-    
-    virtual GameConfig getGameConfig()
-    {
-      return GameConfig();
-    }
-  
-    //slots
-    virtual void nextStep(const Point& point)
-    {
-      Q_UNUSED(point);
+      return nullptr;
     }
     
     virtual void setBoardModel(BoardModel *board)
@@ -77,20 +59,24 @@ namespace KDots
       Q_UNUSED(board);
     }
     
-    virtual void setDifficulty(const KgDifficultyLevel *difficulty)
+    virtual Owner owner() const
     {
-      Q_UNUSED(difficulty);
+      return Owner::NONE;
     }
-        
+    
     virtual bool canUndo() const
     {
       return false;
     }
     
-  protected: //signals
-    virtual void createBoardModel(const GameConfig& config) = 0;
+  public: //slots
+    virtual void onPointAdded(const Point& point) = 0;
+    virtual void onDifficultyChanged(const KgDifficultyLevel *difficulty) = 0;
     
+  protected: //signals
+    virtual void needCreateBoard(const GameConfig& config) = 0;
     virtual void needDestroy() = 0;
+    virtual void needAddPoint(const Point&) = 0;
   };
 }
 
diff --git a/mainwindow.cpp b/mainwindow.cpp
index fe96bea..68e0770 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -118,12 +118,12 @@ namespace KDots
   
   namespace
   {
-    std::shared_ptr<StepQueue> createStepQueue(const GameConfig& config)
+    std::unique_ptr<StepQueue> createStepQueue(const GameConfig& config)
     {
       if (config.m_mode == GameMode::DEFAULT_MODE)
-        return std::make_shared<StepQueue>(config.m_firstOwner);
+        return std::unique_ptr<StepQueue>(new StepQueue(config.m_firstOwner));
       
-      return std::make_shared<ExtraStepQueue>(config.m_firstOwner);
+      return std::unique_ptr<StepQueue>(new ExtraStepQueue(config.m_firstOwner));
     }
   }
 
@@ -143,21 +143,20 @@ namespace KDots
     connect(Kg::difficulty(),
         SIGNAL(currentLevelChanged(const KgDifficultyLevel*)),
         rival.get(),
-        SLOT(setDifficulty(const KgDifficultyLevel*)));
+        SLOT(onDifficultyChanged(const KgDifficultyLevel*)));
     
     m_menu.m_undoAction->setEnabled(rival->canUndo());
     
     connect(rival.get(), SIGNAL(needDestroy()), this, SLOT(endGame()));
     
     m_model = std::unique_ptr<BoardModel>(new BoardModel(config, \
createStepQueue(config))); +    connect(m_menu.m_undoAction, SIGNAL(triggered(bool)), \
m_model.get(), SLOT(undo())); +    connect(m_model.get(), SIGNAL(statusUpdated(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()));
-
-    connect(m_menu.m_undoAction, SIGNAL(triggered(bool)), view.get(), SLOT(undo()));
     
     setCentralWidget(view.get());
     
diff --git a/newgamedialog.cpp b/newgamedialog.cpp
index a5fed5a..afddf21 100644
--- a/newgamedialog.cpp
+++ b/newgamedialog.cpp
@@ -66,8 +66,6 @@ namespace KDots
   {
     if (m_game)
       m_config = m_game->getGameConfig();
-    else
-      m_config = m_rival->getGameConfig();
     
     QDialog::accept();
   }
@@ -77,6 +75,11 @@ namespace KDots
     return m_config;
   }
   
+  void NewGameDialog::onBoardConfigReceived(const GameConfig& config)
+  {
+    m_config = config;
+  }
+  
   void NewGameDialog::pluginWidget()
   {
     m_ui->NextButton->disconnect(this, SLOT(pluginWidget()));
@@ -98,6 +101,11 @@ namespace KDots
     
     m_rival = std::move(pluginInstance->createRival());
     
+    connect(m_rival.get(),
+            SIGNAL(needCreateBoard(const GameConfig&)),
+            this,
+            SLOT(onBoardConfigReceived(const GameConfig&)));
+    
     m_pluginManager->hide();
     
     m_configWidget = m_rival->configureWidget();
@@ -110,12 +118,12 @@ namespace KDots
     
     m_ui->Grid->addWidget(m_configWidget , 0, 0);
     
-    connect(m_configWidget, SIGNAL(needCreateTable(bool)), this, \
SLOT(onNeedCreateTable(bool))); +    connect(m_configWidget, \
SIGNAL(needCreateBoard(bool)), this, SLOT(onNeedCreateBoard(bool)));  
     connect(m_ui->NextButton, SIGNAL(clicked(bool)), this, SLOT(gameWidget()));
   }
   
-  void NewGameDialog::onNeedCreateTable(bool val)
+  void NewGameDialog::onNeedCreateBoard(bool val)
   {
     if (val)
     {
diff --git a/newgamedialog.hpp b/newgamedialog.hpp
index 60cc6a8..17744c6 100644
--- a/newgamedialog.hpp
+++ b/newgamedialog.hpp
@@ -57,7 +57,9 @@ namespace KDots
   private slots:
     void pluginWidget();
     void gameWidget();
-    void onNeedCreateTable(bool);
+    void onNeedCreateBoard(bool);
+    
+    void onBoardConfigReceived(const GameConfig& config);
     
   private:
     Ui::NewGameDialog *m_ui;
diff --git a/pluginmanagerwidget.cpp b/pluginmanagerwidget.cpp
index ad0e3c6..e60db14 100644
--- a/pluginmanagerwidget.cpp
+++ b/pluginmanagerwidget.cpp
@@ -55,7 +55,7 @@ namespace KDots
         this,
         SLOT(onIndexChanged(const QModelIndex&)));
     
-    const QModelIndex& index =model->index(Settings::lastPlugin(), 0);
+    const QModelIndex& index =model->index(0, 0);
     m_ui->PluginList->selectionModel()->select(index, QItemSelectionModel::Select);
     onIndexChanged(index);
   }
diff --git a/plugins/simpleai/plugin.cpp b/plugins/simpleai/plugin.cpp
index 2ec12a8..560d8b1 100644
--- a/plugins/simpleai/plugin.cpp
+++ b/plugins/simpleai/plugin.cpp
@@ -24,5 +24,38 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "plugin.hpp"
+#include <KLocalizedString>
+#include <KgDifficulty>
+
+namespace KDots
+{
+namespace simpleai
+{
+  Plugin::Plugin(QObject *parent)
+    : IPlugin(parent)
+  {
+  }
+
+  std::unique_ptr<IRival> Plugin::createRival()
+  {
+    return std::unique_ptr<IRival>(new Rival);
+  }
+
+  QString Plugin::name() const
+  {
+    return "simpleai";
+  }
+
+  QString Plugin::description() const
+  {
+    return i18n("Playing with the simple AI");
+  }
+  
+  KIcon Plugin::icon() const
+  {
+    return KIcon("games-config-board");
+  }
+}
+}
 
 Q_EXPORT_PLUGIN2(kdots_simpleai, KDots::simpleai::Plugin)
diff --git a/plugins/simpleai/plugin.hpp b/plugins/simpleai/plugin.hpp
index 205d9fe..68f2c14 100644
--- a/plugins/simpleai/plugin.hpp
+++ b/plugins/simpleai/plugin.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_PLUGINS_SIMPLEAI_PLUGIN_HPP
-#define KDOTS_PLUGINS_SIMPLEAI_PLUGIN_HPP
+#pragma once
 #include <interface/iplugin.hpp>
 #include "rival.hpp"
 
@@ -37,33 +36,13 @@ namespace KDots
       Q_OBJECT
       Q_INTERFACES(KDots::IPlugin)
     public:
-      Plugin(QObject *parent = 0)
-        : IPlugin(parent)
-      {
-      }
-
-      std::unique_ptr<IRival> createRival()
-      {
-        return std::unique_ptr<IRival>(new Rival);
-      }
-
-      QString name() const
-      {
-        return "simpleai";
-      }
-
-      QString description() const
-      {
-        return "Playing with the simple AI";
-      }
+      Plugin(QObject *parent = 0);
       
-      KIcon icon() const
-      {
-        return KIcon("games-config-board");
-      }
+      std::unique_ptr<IRival> createRival();
+      QString name() const;
+      QString description() const;
+      KIcon icon() const;
     };
 
   }
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/plugins/simpleai/prioritymap.hpp b/plugins/simpleai/prioritymap.hpp
index 7c81850..e0a7fbf 100644
--- a/plugins/simpleai/prioritymap.hpp
+++ b/plugins/simpleai/prioritymap.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_PLUGINS_SIMPLEAI_PRIORITY_HPP
-#define KDOTS_PLUGINS_SIMPLEAI_PRIORITY_HPP
+#pragma once
 #include <list>
 #include <vector>
 #include <KDebug>
@@ -131,6 +130,4 @@ namespace KDots
       const std::list<MapData>& priorityMap();
     };
   }
-}
-
-#endif
+}
\ No newline at end of file
diff --git a/plugins/simpleai/rival.cpp b/plugins/simpleai/rival.cpp
index 372657b..948f03b 100644
--- a/plugins/simpleai/rival.cpp
+++ b/plugins/simpleai/rival.cpp
@@ -55,12 +55,9 @@ namespace KDots
       Kg::difficulty()->setEditable(true);
     }
     
-    bool Rival::isAllow() const
+    Owner Rival::owner() const
     {
-      if(!m_board)
-        return false;
-      
-      return m_board->stepQueue().getCurrentOwner() == \
m_board->stepQueue().firstOwner(); +      return m_current;
     }
     
     bool Rival::hasMask(const Graph& graph, const Point& point, const MapData& mask, \
const Owner current) @@ -186,7 +183,7 @@ namespace KDots
       }
     }
     
-    void Rival::setDifficulty(const KgDifficultyLevel *level)
+    void Rival::onDifficultyChanged(const KgDifficultyLevel *level)
     {
       switch (level->standardLevel())
       {
@@ -201,7 +198,6 @@ namespace KDots
         break;
       }
     }
-
     
     bool Rival::hasCaptured(const KDots::Point& point, KDots::Owner current) const
     {
@@ -229,14 +225,9 @@ namespace KDots
       return false;
     }
     
-    std::vector<Point> Rival::possibleMoves() const
-    {
-      return m_points;
-    }
-    
-    void Rival::nextStep(const Point& point)
+    void Rival::onPointAdded(const Point& point)
     {
-      if(isAllow())
+      if (m_board->stepQueue().getCurrentOwner() == \
m_board->stepQueue().firstOwner())  return;
       
       int min_x = point.m_x - 1, min_y = point.m_y - 1;
@@ -272,7 +263,7 @@ namespace KDots
       if(!m_points.empty())
       {
         std::srand(std::time(NULL));
-        m_board->pushPoint(m_points[std::rand() % m_points.size()]);
+        emit needAddPoint(m_points[std::rand() % m_points.size()]);
       }
     }
     
diff --git a/plugins/simpleai/rival.hpp b/plugins/simpleai/rival.hpp
index 0e4b535..55a74c9 100644
--- a/plugins/simpleai/rival.hpp
+++ b/plugins/simpleai/rival.hpp
@@ -23,10 +23,10 @@
  *(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_PLUGINS_SIMPLEAI_RIVAL_HPP
-#define KDOTS_PLUGINS_SIMPLEAI_RIVAL_HPP
+#pragma once
 #include <memory>
 #include <QLabel>
+#include <point.hpp>
 #include <interface/irival.hpp>
 
 namespace KDots
@@ -47,18 +47,16 @@ namespace KDots
       std::vector<Point> m_points;
     public:
       Rival(QObject *parent = 0);
-      ~Rival() {}
       
-      bool isAllow() const;
-      static bool hasMask(const Graph& graph, const Point& point, const MapData& \
mask, const Owner current); +      Owner owner() const;
       
-      std::vector<Point> possibleMoves() const;
+      static bool hasMask(const Graph& graph, const Point& point, const MapData& \
mask, const Owner current);  
       void setBoardModel(BoardModel *board);
       
     public slots:
-      void nextStep(const Point& point);
-      void setDifficulty(const KgDifficultyLevel *level);
+      void onPointAdded(const Point& point);
+      void onDifficultyChanged(const KgDifficultyLevel *level);
       
     private:
       float calcPriority(const Point& point);
@@ -66,10 +64,9 @@ namespace KDots
       bool hasCaptured(const Point& point, Owner current) const;
       
     signals:
-      void createBoardModel(const GameConfig& config);
+      void needCreateBoard(const GameConfig& config);
       void needDestroy();
+      void needAddPoint(const Point&);
     };
   }
 }
-
-#endif
diff --git a/plugins/singlepc/plugin.cpp b/plugins/singlepc/plugin.cpp
index 8057769..5cdcd43 100644
--- a/plugins/singlepc/plugin.cpp
+++ b/plugins/singlepc/plugin.cpp
@@ -24,6 +24,59 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "plugin.hpp"
+#include <KLocalizedString>
+#include <KgDifficulty>
+
+namespace KDots
+{
+namespace singlepc
+{
+  Rival::Rival(QObject *parent)
+    : IRival(parent)
+  {
+    Kg::difficulty()->setEditable(false);
+  }
+
+  bool Rival::canUndo() const
+  {
+    return true;
+  }
+      
+  void Rival::onPointAdded(const Point&)
+  {
+  }
+  
+  void Rival::onDifficultyChanged(const KgDifficultyLevel*)
+  {
+  }
+  
+  
+  Plugin::Plugin(QObject *parent)
+    : IPlugin(parent)
+  {
+  }
+
+  std::unique_ptr<IRival> Plugin::createRival()
+  {
+    return std::unique_ptr<IRival>(new Rival);
+  }
+
+  QString Plugin::name() const
+  {
+    return "singlepc";
+  }
+
+  QString Plugin::description() const
+  {
+    return i18n("Playing in the single PC");
+  }
+  
+  KIcon Plugin::icon() const
+  {
+    return KIcon();
+  }
+}
+}
 
 Q_EXPORT_PLUGIN2(kdots_singlepc, KDots::singlepc::Plugin)
 
diff --git a/plugins/singlepc/plugin.hpp b/plugins/singlepc/plugin.hpp
index 2ade441..0629d13 100644
--- a/plugins/singlepc/plugin.hpp
+++ b/plugins/singlepc/plugin.hpp
@@ -23,9 +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_PLUGINS_SINGLEPC_PLUGIN_HPP
-#define KDOTS_PLUGINS_SINGLEPC_PLUGIN_HPP
-#include <KgDifficulty>
+#pragma once
 #include <interface/iplugin.hpp>
 #include <interface/irival.hpp>
 
@@ -38,30 +36,18 @@ namespace KDots
       Q_OBJECT
       Q_INTERFACES(KDots::IRival)
     public:
-      Rival(QObject *parent = 0)
-        : IRival(parent)
-      {
-        Kg::difficulty()->setEditable(false);
-      }
-
-      bool isAllow() const
-      {
-        return true;
-      }
-    
-      bool canUndo() const
-      {
-        return true;
-      }
+      Rival(QObject *parent = 0);
+      
+      bool canUndo() const;
 
     public slots:
-      void nextStep(const Point& point)
-      {
-        Q_UNUSED(point);
-      }
+      void onPointAdded(const Point& point);
+      void onDifficultyChanged(const KgDifficultyLevel *difficulty);
+
     signals:
-      void createBoardModel(const GameConfig& config);
+      void needCreateBoard(const GameConfig& config);
       void needDestroy();
+      void needAddPoint(const Point&);
     };
 
     class KDE_EXPORT Plugin : public KDots::IPlugin
@@ -69,33 +55,12 @@ namespace KDots
       Q_OBJECT
       Q_INTERFACES(KDots::IPlugin)
     public:
-      Plugin(QObject *parent = 0)
-        : IPlugin(parent)
-      {
-      }
-
-      std::unique_ptr<IRival> createRival()
-      {
-        return std::unique_ptr<IRival>(new Rival);
-      }
-
-      QString name() const
-      {
-        return "singlepc";
-      }
-
-      QString description() const
-      {
-        return "Playing in the single PC";
-      }
-      
-      KIcon icon() const
-      {
-        return KIcon();
-      }
+      Plugin(QObject *parent = 0);
+      std::unique_ptr<IRival> createRival();
+      QString name() const;
+      QString description() const;
+      KIcon icon() const;
     };
 
   }
-}
-
-#endif
+}
\ 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