Menu items in correct places 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 #include <QDebug>
26
27 Levelset::Levelset()
28 {
29
30 }
31
32 Levelset::Levelset(QString name, QList<Level> levelList)
33 {
34     name_ = name;
35
36     levels_ = levelList;
37 }
38
39
40 bool Levelset::isValid()
41 {
42     if (name_.isEmpty())
43         return false;
44
45     if (levels_.isEmpty())
46         return false;
47
48     return true;
49 }
50
51 QString Levelset::getName()
52 {
53     return name_;
54 }
55
56 int Levelset::numberOfLevels()
57 {
58     return levels_.length();
59 }
60
61 Level Levelset::getLevel(int index)
62 {
63
64     return levels_.value(index); //Returns a default constructed Level if called with invalid index
65
66 }
67
68 int Levelset::getTotalHighScore()
69 {
70     QSettings settings;
71     settings.beginGroup(name_);
72     return settings.value("TotalHighScore",900*1000*100).toInt();
73 }
74
75 void Levelset::setTotalHighScore(int highscore)
76 {
77     QSettings settings;
78
79     settings.beginGroup(name_);
80     settings.setValue("TotalHighScore", highscore);
81
82 }
83
84 int Levelset::getLevelHighScore(int index)
85 {
86     QSettings settings;
87     QString group = name_;
88     group.append("/LevelHighScore");
89     settings.beginGroup(group);
90
91     qDebug() << group;
92
93     return settings.value(QString(index),900*1000).toInt();
94 }
95
96 void Levelset::setLevelHighScore(int index, int highScore)
97 {
98     QSettings settings;
99     QString group = name_;
100     group.append("/LevelHighScore");
101     settings.beginGroup(group);
102
103     qDebug() << group;
104
105     settings.setValue(QString(index),highScore);
106 }