From 27c05355f4e953f836bcd846ceb7fcf3226f154f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Tue, 6 Sep 2011 18:19:29 +0300 Subject: [PATCH] Added Levelset class 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 | 8 +++-- levelset.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ levelset.h | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 levelset.cpp create mode 100644 levelset.h diff --git a/ghostsoverboard.pro b/ghostsoverboard.pro index e3fb626..c08d156 100644 --- a/ghostsoverboard.pro +++ b/ghostsoverboard.pro @@ -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 index 0000000..7491dfd --- /dev/null +++ b/levelset.cpp @@ -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 . + +**************************************************************************/ + +#include "levelset.h" +#include + +Levelset::Levelset() +{ + +} + +Levelset::Levelset(QString name, QList 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 index 0000000..69e0469 --- /dev/null +++ b/levelset.h @@ -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 . + +**************************************************************************/ + +#ifndef LEVELSET_H +#define LEVELSET_H + +#include "level.h" +#include +#include + +class Levelset +{ +public: + Levelset(); + + Levelset(QString name, QList 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 levels_; + +}; + +#endif // LEVELSET_H -- 1.7.9.5