#include <QTextStream>
#include <QStringList>
+#include <QDebug>
+
Statistics *Statistics::instance_ = 0;
Statistics::Statistics(QObject *parent) :
{
qreal count = 0.0;
if(games_.at(difficulty) > 0) {
- count = moves_.at(difficulty) / static_cast<qreal>(games_.at(difficulty));
+ count = (moves_.at(difficulty) / games_.at(difficulty));
}
return count;
void Statistics::addNewScore(int moves, Difficulty difficulty)
{
if(moves_.count() >= difficulty) {
- moves_[difficulty] += (moves_[difficulty] + moves);
+ moves_[difficulty] += moves;
}
if(maxMoves_.count() >= difficulty) {
.arg(STATS_FILE));
if(!file.exists()) {
+ qDebug() << __PRETTY_FUNCTION__ << "No settings file";
return;
}
void Statistics::saveFile()
{
+ QDir dir(QString("%1/%2")
+ .arg(QDir::homePath())
+ .arg(HOME_DIRECTORY));
+ if(!dir.exists()) {
+ dir.mkpath(QString("%1/%2")
+ .arg(QDir::homePath())
+ .arg(HOME_DIRECTORY));
+ }
+
QFile file(QString("%1/%2/%3")
.arg(QDir::homePath())
.arg(HOME_DIRECTORY)
file.close();
}
+
+void Statistics::resetStatistics()
+{
+ moves_.clear();
+ minMoves_.clear();
+ maxMoves_.clear();
+ games_.clear();
+
+ moves_ << 0 << 0;
+ minMoves_ << 0 << 0;
+ maxMoves_ << 0 << 0;
+ games_ << 0 << 0;
+
+ saveFile();
+}