Commit c2fde8d1 authored by Denis Kuplyakov's avatar Denis Kuplyakov

KReversiView animation time now is synced with KReversiGame delay

Delay now is returned from setAnimationSpeed() function and passed to
KReversiGame.
Fixed compilation error.
Fixed prepare()-ready() connection bug.
parent aa33d669
......@@ -54,7 +54,7 @@ struct KReversiMove: public KReversiPos {
}
};
ChipColor opponentColorFor(ChipColor color)
static ChipColor opponentColorFor(ChipColor color)
{
if (color == NoColor)
return NoColor;
......
......@@ -40,9 +40,6 @@ KReversiGame::KReversiGame(KReversiPlayer *blackPlayer, KReversiPlayer *whitePla
m_score[White] = m_score[Black] = 2;
whitePlayer->prepare(this);
blackPlayer->prepare(this);
m_player[White] = whitePlayer;
m_player[Black] = blackPlayer;
......@@ -59,6 +56,9 @@ KReversiGame::KReversiGame(KReversiPlayer *blackPlayer, KReversiPlayer *whitePla
connect(whitePlayer, SIGNAL(ready()), this, SLOT(whiteReady()));
m_engine = new Engine(1);
whitePlayer->prepare(this);
blackPlayer->prepare(this);
}
KReversiGame::~KReversiGame()
......@@ -287,16 +287,18 @@ void KReversiGame::onDelayTimer()
void KReversiGame::blackReady()
{
qDebug() << "Black ready";
m_isReady[Black] = true;
if (m_isReady[White])
blackPlayer->takeTurn();
m_player[Black]->takeTurn();
}
void KReversiGame::whiteReady()
{
qDebug() << "White ready";
m_isReady[White] = true;
if (m_isReady[Black])
blackPlayer->takeTurn();
m_player[Black]->takeTurn();
}
KReversiMove KReversiGame::getHint() const
......
......@@ -88,7 +88,7 @@ void KReversiView::setShowBoardLabels(bool show)
updateBoard();
}
void KReversiView::setAnimationSpeed(int speed)
int KReversiView::setAnimationSpeed(int speed)
{
int value = ANIMATION_SPEED_NORMAL;
switch (speed) {
......@@ -106,6 +106,7 @@ void KReversiView::setAnimationSpeed(int speed)
m_delay = value;
m_qml_root->setProperty("chipsAnimationTime", value);
return value;
}
KReversiView::~KReversiView()
......
......@@ -74,8 +74,10 @@ public:
* Sets the animation speed
*
* @param speed 0 - slow, 1 - normal, 2 - fast
*
* @return time for animation in milliseconds to pass it to KReversiGame
*/
void setAnimationSpeed(int speed);
int setAnimationSpeed(int speed);
/**
* Destructor used to delete game object owned by class
......
......@@ -164,7 +164,7 @@ void KReversiMainWindow::levelChanged()
void KReversiMainWindow::slotAnimSpeedChanged(int speed)
{
m_view->setAnimationSpeed(speed);
m_game->setDelay(m_view->setAnimationSpeed(speed));
Preferences::setAnimationSpeed(speed);
Preferences::self()->writeConfig();
}
......@@ -239,7 +239,7 @@ void KReversiMainWindow::slotNewGame()
QString chipsPrefix = Preferences::useColoredChips() ? QLatin1String("chip_color") : QLatin1String("chip_bw");
m_view = new KReversiView(m_game, this);
setCentralWidget(m_view);
m_view->setAnimationSpeed(Preferences::animationSpeed());
m_game->setDelay(m_view->setAnimationSpeed(Preferences::animationSpeed()));
connect(m_view, SIGNAL(moveFinished()), SLOT(slotMoveFinished()));
} else {
m_view->setGame(m_game);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment