Best Score
[qmemory] / mainwindow.cpp
index a508562..70fd57c 100644 (file)
@@ -3,12 +3,14 @@
 #include <QMessageBox>
 #include <QDebug>
 #include <QSound>
+#include <QSettings>
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
 {
-
+    bestScore=0;
+    readSettings();
     ui->setupUi(this);
     statusLed = new QLed(ui->verticalLayoutWidget);
     ui->horizontalLayout_4->insertWidget(0,statusLed);
@@ -58,8 +60,20 @@ MainWindow::MainWindow(QWidget *parent) :
     //showMaximized();
 }
 void MainWindow::sbagliato(int score){
-    QString sscore("Score ");
+
+    if(bestScore<= score){
+        bestScore=score;
+        writeSettings();
+        QString sscore("This is Best Score ");
+        sscore.append(QString::number(score));
+        QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
+        //tread.genera();
+        exit(0);
+    }
+    QString sscore("Your Score: ");
     sscore.append(QString::number(score));
+    sscore.append("\n Best score: ");
+    sscore.append(QString::number(bestScore));
     QMessageBox::warning(this, tr("End Game"),sscore,QMessageBox::Escape);
     //tread.genera();
     exit(0);
@@ -206,4 +220,17 @@ void MainWindow::changeEvent(QEvent *e)
         break;
     }
 }
+void MainWindow::writeSettings()
+{
+    QSettings settings("Emmynet Inc.", "QMemory");
+    settings.setValue("bestscore",bestScore);
+
+}
+
+void MainWindow::readSettings()
+{
+    QSettings settings("Emmynet Inc.", "QMemory");
+    bestScore=(settings.value("bestscore").toInt());
+
+}