Best Score
authorEmmanuel Granatello <emmanuel.granatello@intecs.it>
Mon, 1 Mar 2010 11:33:50 +0000 (12:33 +0100)
committerEmmanuel Granatello <emmanuel.granatello@intecs.it>
Mon, 1 Mar 2010 11:33:50 +0000 (12:33 +0100)
Inserita la funzionalità di best score utilizzando i QSetting

mainwindow.cpp
mainwindow.h
moc_mainwindow.cpp
moc_mainwindow.o [new file with mode: 0644]

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());
+
+}
 
index e1ab34a..41c929b 100644 (file)
@@ -35,6 +35,11 @@ signals:
 protected:
     void changeEvent(QEvent *e);
 
+private:
+    void writeSettings();
+    void readSettings();
+
+    int bestScore;
     Ui::MainWindow *ui;
     QList<bool> sequenza;
     TestThread tread;
index 162f4d6..5d1d827 100644 (file)
@@ -1,7 +1,7 @@
 /****************************************************************************
 ** Meta object code from reading C++ file 'mainwindow.h'
 **
-** Created: Fri Feb 26 16:31:33 2010
+** Created: Mon Mar 1 12:31:40 2010
 **      by: The Qt Meta Object Compiler version 62 (Qt 4.6.1)
 **
 ** WARNING! All changes made in this file will be lost!
diff --git a/moc_mainwindow.o b/moc_mainwindow.o
new file mode 100644 (file)
index 0000000..0f7a29a
Binary files /dev/null and b/moc_mainwindow.o differ