Added Levelset class
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 6 Sep 2011 15:19:29 +0000 (18:19 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 6 Sep 2011 15:19:29 +0000 (18:19 +0300)
Contains the name and levels of a levelset and access to highscores of
the set and indivisual levels. The highscores are stored in QSettings.
Each set must have an unique name, or else the highscores will be mixed.
The class is not used yet.

Conflicts:

ghostsoverboard.pro

ghostsoverboard.pro
levelset.cpp [new file with mode: 0644]
levelset.h [new file with mode: 0644]

index e3fb626..c08d156 100644 (file)
@@ -19,7 +19,8 @@ SOURCES += main.cpp\
     timercontrolledgraphicspixmapobject.cpp \
     octopus.cpp \
     level.cpp \
-    seaview.cpp
+    seaview.cpp \
+    levelset.cpp
 
 HEADERS  += \
     orientationcontrolledgraphicspixmapobject.h \
@@ -29,7 +30,8 @@ HEADERS  += \
     timercontrolledgraphicspixmapobject.h \
     octopus.h \
     level.h \
-    seaview.h
+    seaview.h \
+    levelset.h
 
 CONFIG += mobility
 MOBILITY = sensors
@@ -87,3 +89,5 @@ unix:!symbian:!maemo5 {
     desktopfile.path = /usr/share/applications
     INSTALLS += desktopfile
 }
+
+
diff --git a/levelset.cpp b/levelset.cpp
new file mode 100644 (file)
index 0000000..7491dfd
--- /dev/null
@@ -0,0 +1,94 @@
+/**************************************************************************
+        Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
+
+        Copyright (C) 2011  Heli Hyvättinen
+
+        This file is part of Ghosts Overboard
+
+        Ghosts Overboard is free software: you can redistribute it and/or modify
+        it under the terms of the GNU General Public License as published by
+        the Free Software Foundation, either version 2 of the License, or
+        (at your option) any later version.
+
+        This program is distributed in the hope that it will be useful,
+        but WITHOUT ANY WARRANTY; without even the implied warranty of
+        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        GNU General Public License for more details.
+
+        You should have received a copy of the GNU General Public License
+        along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************/
+
+#include "levelset.h"
+#include <QSettings>
+
+Levelset::Levelset()
+{
+
+}
+
+Levelset::Levelset(QString name, QList<Level> levelList)
+{
+    name_ = name;
+
+    levels_ = levelList;
+}
+
+
+bool Levelset::isValid()
+{
+    if (name_.isEmpty())
+        return false;
+
+    if (levels_.isEmpty())
+        return false;
+
+    return true;
+}
+
+int Levelset::numberOfLevels()
+{
+    return levels_.length();
+}
+
+Level Levelset::getLevel(int index)
+{
+
+    return levels_.value(index); //Returns a default constructed Level if called with invalid index
+
+}
+
+int Levelset::getTotalHighScore()
+{
+    QSettings settings;
+    settings.beginGroup(name_);
+    return settings.value("TotalHighScore",54000*10).toInt();
+}
+
+void Levelset::setTotalHighScore(int highscore)
+{
+    QSettings settings;
+
+    settings.beginGroup(name_);
+    settings.setValue("TotalHighScore", highscore);
+
+}
+
+int Levelset::getLevelHighScore(int index)
+{
+    QSettings settings;
+    QString group = name_.append("/LevelHighScore");
+    settings.beginGroup(group);
+
+    return settings.value(QString(index),54000).toInt();
+}
+
+void Levelset::setLevelHighScore(int index, int highScore)
+{
+    QSettings settings;
+    QString group = name_.append("/LevelHighScore");
+    settings.beginGroup(group);
+
+    settings.setValue(QString(index),highScore);
+}
diff --git a/levelset.h b/levelset.h
new file mode 100644 (file)
index 0000000..69e0469
--- /dev/null
@@ -0,0 +1,62 @@
+/**************************************************************************
+        Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
+
+        Copyright (C) 2011  Heli Hyvättinen
+
+        This file is part of Ghosts Overboard
+
+        Ghosts Overboard is free software: you can redistribute it and/or modify
+        it under the terms of the GNU General Public License as published by
+        the Free Software Foundation, either version 2 of the License, or
+        (at your option) any later version.
+
+        This program is distributed in the hope that it will be useful,
+        but WITHOUT ANY WARRANTY; without even the implied warranty of
+        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        GNU General Public License for more details.
+
+        You should have received a copy of the GNU General Public License
+        along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************/
+
+#ifndef LEVELSET_H
+#define LEVELSET_H
+
+#include "level.h"
+#include <QList>
+#include <QString>
+
+class Levelset
+{
+public:
+    Levelset();
+
+    Levelset(QString name, QList<Level> levelList);
+
+    bool isValid();
+
+    QString getName();
+
+    Level getLevel(int index);
+
+    int numberOfLevels();
+
+    int getTotalHighScore();
+
+    void setTotalHighScore(int highScore);
+
+    int getLevelHighScore(int index);
+
+    void setLevelHighScore(int index, int highScore);
+
+
+private:
+
+    QString name_;
+
+    QList<Level> levels_;
+
+};
+
+#endif // LEVELSET_H