Advances to the next level again
[ghostsoverboard] / levelset.cpp
1 /**************************************************************************
2         Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
8         Ghosts Overboard is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23 #include "levelset.h"
24 #include <QSettings>
25
26 Levelset::Levelset()
27 {
28
29 }
30
31 Levelset::Levelset(QString name, QList<Level> levelList)
32 {
33     name_ = name;
34
35     levels_ = levelList;
36 }
37
38
39 bool Levelset::isValid()
40 {
41     if (name_.isEmpty())
42         return false;
43
44     if (levels_.isEmpty())
45         return false;
46
47     return true;
48 }
49
50 int Levelset::numberOfLevels()
51 {
52     return levels_.length();
53 }
54
55 Level Levelset::getLevel(int index)
56 {
57
58     return levels_.value(index); //Returns a default constructed Level if called with invalid index
59
60 }
61
62 int Levelset::getTotalHighScore()
63 {
64     QSettings settings;
65     settings.beginGroup(name_);
66     return settings.value("TotalHighScore",900*100).toInt();
67 }
68
69 void Levelset::setTotalHighScore(int highscore)
70 {
71     QSettings settings;
72
73     settings.beginGroup(name_);
74     settings.setValue("TotalHighScore", highscore);
75
76 }
77
78 int Levelset::getLevelHighScore(int index)
79 {
80     QSettings settings;
81     QString group = name_.append("/LevelHighScore");
82     settings.beginGroup(group);
83
84     return settings.value(QString(index),900).toInt();
85 }
86
87 void Levelset::setLevelHighScore(int index, int highScore)
88 {
89     QSettings settings;
90     QString group = name_.append("/LevelHighScore");
91     settings.beginGroup(group);
92
93     settings.setValue(QString(index),highScore);
94 }