X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=classes%2Fchessclock.cpp;h=308d82d19ddf44fe7dd541d749d12c7b4cd69053;hb=ca6853daf22068621981987588b9d670f03a5264;hp=a0d884face89b1a57d5a341485cb29fa43036c37;hpb=a08f83a286b96562233e9753c9fb189cb1126fc0;p=chessclock diff --git a/classes/chessclock.cpp b/classes/chessclock.cpp index a0d884f..308d82d 100644 --- a/classes/chessclock.cpp +++ b/classes/chessclock.cpp @@ -79,14 +79,14 @@ void ChessClock::continueTurn() TurnInformation* ChessClock::endTurn() { - status_ = NotRunning; updateTimer_.stop(); - // Update turn time - currentTurn_->addTime( clockTime_.restart()); // Count time played timePlayedBeforeTurn_ = getTimePlayed(); // Count time available + // This update current turn timeAvailableBeforeTurn_ = getTimeAvailable(); + + status_ = NotRunning; updateClock(); // Close and return turn information @@ -109,19 +109,18 @@ int ChessClock::getTimeAvailable() if( currentTurn_) { // Update turn time - currentTurn_->addTime( clockTime_.restart()); - return timeAvailableBeforeTurn_-currentTurn_->getDuration(); + return timeAvailableBeforeTurn_-currentTurnPlayed(); } else return timeAvailableBeforeTurn_; } -int ChessClock::getTimePlayed() const +int ChessClock::getTimePlayed() { // Count time played time if( currentTurn_ ) - return timePlayedBeforeTurn_ + currentTurn_->getDuration(); + return timePlayedBeforeTurn_ + currentTurnPlayed(); else return timePlayedBeforeTurn_; } @@ -138,6 +137,22 @@ void ChessClock::addTime(int msecs) timeAvailableBeforeTurn_ += msecs; } +int ChessClock::currentTurnPlayed() +{ + if( currentTurn_ ) + { + // Update current time + if( status_ == Running ) + currentTurn_->addTime( clockTime_.restart()); + + // Return current time + return currentTurn_->getDuration(); + } + else + // No current turn! + return 0; +} + void ChessClock::updateClock() { // Check loser