[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bknights=5D_src=3A_Implement_the_computer_delay_in_M?=
From: Miha Čančula <miha.cancula () gmail ! com>
Date: 2011-02-13 16:23:37
Message-ID: 20110213162337.A9FE8A60DE () git ! kde ! org
[Download RAW message or body]
Git commit 151ec93815a5c16f42cc8808347ddb895768b2c9 by Miha Čančula.
Committed on 13/02/2011 at 13:23.
Pushed by mihac into branch 'master'.
Implement the computer delay in Manager.
M +20 -4 src/gamemanager.cpp
M +8 -6 src/gamemanager.h
M +2 -0 src/rules/rules.h
http://commits.kde.org/knights/151ec93815a5c16f42cc8808347ddb895768b2c9
diff --git a/src/gamemanager.cpp b/src/gamemanager.cpp
index 0fb8f7f..33e6c85 100644
--- a/src/gamemanager.cpp
+++ b/src/gamemanager.cpp
@@ -29,6 +29,8 @@
#include <KLocale>
#include "rules/rules.h"
#include "rules/chessrules.h"
+#include <QTimer>
+#include <settings.h>
using namespace Knights;
@@ -306,6 +308,7 @@ bool Manager::timeControlEnabled(Color color) const
void Manager::undo()
{
+ sendPendingMove();
Q_D(const GameManager);
Offer o;
o.action = ActionUndo;
@@ -326,6 +329,7 @@ void Manager::undo()
void Manager::redo()
{
+ sendPendingMove();
Move m = nextRedoMove();
Protocol::white()->move ( m );
Protocol::black()->move ( m );
@@ -384,10 +388,8 @@ void Manager::moveByProtocol(const Move& move)
{
startTime();
}
- Protocol::byColor ( oppositeColor ( d->activePlayer ) )->move ( m );
- emit pieceMoved ( m );
- rules()->moveMade ( m );
- changeActivePlayer();
+ pendingMove = m;
+ QTimer::singleShot ( Settings::computerDelay(), this, SLOT(sendPendingMove()) );
}
void Manager::protocolInitSuccesful()
@@ -559,6 +561,20 @@ bool Manager::canRedo() const
return !d->moveUndoStack.isEmpty();
}
+void Manager::sendPendingMove()
+{
+ if ( pendingMove.isValid() )
+ {
+ Q_D(const GameManager);
+ Protocol::byColor ( oppositeColor ( d->activePlayer ) )->move ( pendingMove );
+ emit pieceMoved ( pendingMove );
+ rules()->moveMade ( pendingMove );
+ changeActivePlayer();
+ pendingMove = Move();
+ }
+}
+
+
diff --git a/src/gamemanager.h b/src/gamemanager.h
index 0ae7bf2..fe74e1e 100644
--- a/src/gamemanager.h
+++ b/src/gamemanager.h
@@ -23,6 +23,8 @@
#define KNIGHTS_GAMEMANAGER_H
#include <core/piece.h>
+#include <core/move.h>
+
#include <QtCore/QObject>
#include <QtCore/QTime>
@@ -31,12 +33,8 @@
namespace Knights {
-class Protocol;
-
-
-class Rules;
-
-
+ class Protocol;
+ class Rules;
class Move;
class GameManagerPrivate;
@@ -118,6 +116,9 @@ private:
void stopTime();
Protocol* local();
+
+private slots:
+ void sendPendingMove();
protected:
virtual void timerEvent(QTimerEvent* );
@@ -151,6 +152,7 @@ public slots:
private:
GameManagerPrivate* d_ptr;
+ Move pendingMove;
Q_DECLARE_PRIVATE(GameManager)
diff --git a/src/rules/rules.h b/src/rules/rules.h
index 9ad8795..9a8d76e 100644
--- a/src/rules/rules.h
+++ b/src/rules/rules.h
@@ -25,6 +25,7 @@
#include "core/piece.h"
#include "board.h"
+#include <KDebug>
template<class Key, class T > class QMap;
namespace Knights
@@ -59,6 +60,7 @@ namespace Knights
virtual void setGrid ( QMap<Pos, Piece*>* grid )
{
+ kDebug() << "Setting Grid";
m_grid = grid;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic