Commit e0f52add authored by Piotr Kąkol's avatar Piotr Kąkol Committed by Albert Astals Cid
Browse files

Add minimal number of moves statistics

Summary:
Statistics that displays the minimal number of moves that a player used to win a game. This could be used to make the game more competitive - comparing your score to other people's.

The number is set to -1 (which is unachievable) when reseting the statistics and an infinity symbol is then displayed.

Reviewers: #kde_games

Subscribers: aacid, kde-games-devel

Differential Revision: https://phabricator.kde.org/D25642
parent 7408d2bb
......@@ -1738,6 +1738,7 @@ void DealerScene::recordGameStatistics()
QString maxWinStreakKey = QStringLiteral("maxwinstreak%1").arg( id );
QString loseStreakKey = QStringLiteral("loosestreak%1").arg( id );
QString maxLoseStreakKey = QStringLiteral("maxloosestreak%1").arg( id );
QString minMovesKey = QStringLiteral("minmoves%1").arg( id );
KConfigGroup config(KSharedConfig::openConfig(), scores_group);
......@@ -1747,6 +1748,7 @@ void DealerScene::recordGameStatistics()
int maxWinStreak = config.readEntry( maxWinStreakKey, 0 );
int loseStreak = config.readEntry( loseStreakKey, 0 );
int maxLoseStreak = config.readEntry( maxLoseStreakKey, 0 );
int minMoves = config.readEntry( minMovesKey, -1 );
++totalPlayed;
......@@ -1756,6 +1758,10 @@ void DealerScene::recordGameStatistics()
++winStreak;
maxWinStreak = qMax( winStreak, maxWinStreak );
loseStreak = 0;
if ( minMoves < 0 )
minMoves = moveCount();
else
minMoves = qMin( minMoves, moveCount() );
}
else
{
......@@ -1770,6 +1776,7 @@ void DealerScene::recordGameStatistics()
config.writeEntry( maxWinStreakKey, maxWinStreak );
config.writeEntry( loseStreakKey, loseStreak );
config.writeEntry( maxLoseStreakKey, maxLoseStreak );
config.writeEntry( minMovesKey, minMoves );
m_statisticsRecorded = true;
}
......
......@@ -122,6 +122,11 @@ void StatisticsDialog::setGameType(int gameIndex)
ui->Won->setText( QString::number(w));
ui->WinStreak->setText( QString::number( cg.readEntry(QStringLiteral("maxwinstreak%1").arg(gameIndex), 0)));
ui->LoseStreak->setText( QString::number( cg.readEntry(QStringLiteral("maxloosestreak%1").arg(gameIndex), 0)));
int minMoves = cg.readEntry(QStringLiteral("minmoves%1").arg(gameIndex), -1);
if(minMoves < 0)
ui->MinMoves->setText("∞");
else
ui->MinMoves->setText(QString::number(minMoves));
unsigned int l = cg.readEntry(QStringLiteral("loosestreak%1").arg(gameIndex),0);
if (l)
ui->CurrentStreak->setText( i18np("1 loss", "%1 losses", l) );
......@@ -141,6 +146,7 @@ void StatisticsDialog::resetStats()
cg.writeEntry(QStringLiteral("maxloosestreak%1").arg(gameIndex),0);
cg.writeEntry(QStringLiteral("loosestreak%1").arg(gameIndex),0);
cg.writeEntry(QStringLiteral("winstreak%1").arg(gameIndex),0);
cg.writeEntry(QStringLiteral("minmoves%1").arg(gameIndex),-1);
cg.sync();
setGameType(gameIndex);
......
......@@ -141,6 +141,23 @@
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Minimal number of moves:</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2" >
<widget class="QLabel" name="MinMoves" >
<property name="text" >
<string/>
</property>
<property name="alignment" >
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
......
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