Commit 6e7beadd authored by Denis Kuplyakov's avatar Denis Kuplyakov

Fixed dublicate of history entries after move skip

Now KReversiGame handling history logging. MainWindow simply get history
from KReversiGame instead of maintaining it
parent b2f1b076
......@@ -264,6 +264,14 @@ void KReversiGame::setDelay(int delay)
m_delay = delay;
}
MoveList KReversiGame::getHistory() const
{
MoveList l;
for (int i = 0; i < m_undoStack.size(); i++)
l.push_back(m_undoStack.at(i).at(0));
return l;
}
void KReversiGame::blackPlayerMove(KReversiMove move)
{
qDebug() << "Game: black move";
......
......@@ -112,6 +112,11 @@ public:
* Sets animation times from players
*/
void setDelay(int delay);
/**
* @return History of moves as MoveList
*/
MoveList getHistory() const;
private slots:
/**
* Starts next player turn.
......
......@@ -300,15 +300,20 @@ void KReversiMainWindow::slotMoveFinished()
//TODO check computer-computer
m_undoAct->setEnabled(m_game->canUndo());
// add last move to history list
// KReversiMove move = m_game->getLastMove();
// QString numStr = QString::number(m_historyView->count() + 1) + QLatin1String(". ");
// m_historyView->addItem(numStr + moveToString(move));
// QListWidgetItem *last = m_historyView->item(m_historyView->count() - 1);
// m_historyView->setCurrentItem(last);
// m_historyView->scrollToItem(last);
// statusBar()->changeItem(m_game->isComputersTurn() ? opponentName() : i18n("Your turn."), 0);
MoveList history = m_game->getHistory();
m_historyView->clear();
for (int i = 0; i < history.size(); i++) {
QString numStr = QString::number(i + 1) + QLatin1String(". ");
m_historyView->addItem(numStr + moveToString(history.at(i)));
}
QListWidgetItem *last = m_historyView->item(m_historyView->count() - 1);
m_historyView->setCurrentItem(last);
m_historyView->scrollToItem(last);
//statusBar()->changeItem(m_game->isComputersTurn() ? opponentName() : i18n("Your turn."), 0);
updateScores();
}
......
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