1 | /******************************************************************* |
2 | * |
3 | * Copyright 2006-2009 Dmitry Suzdalev <dimsuz@gmail.com> |
4 | * |
5 | * This file is part of the KDE project "KAtomic" |
6 | * |
7 | * KAtomic is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2, or (at your option) |
10 | * any later version. |
11 | * |
12 | * KAtomic is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with KAtomic; see the file COPYING. If not, write to |
19 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | * |
22 | ********************************************************************/ |
23 | #ifndef KATOMIC_LEVELSET_H |
24 | #define KATOMIC_LEVELSET_H |
25 | |
26 | #include <QString> |
27 | #include <QList> |
28 | |
29 | #include <KSharedConfig> |
30 | |
31 | #include "commondefs.h" |
32 | |
33 | class Molecule; |
34 | |
35 | /** |
36 | * Class that represents a KAtomic level |
37 | */ |
38 | class LevelData |
39 | { |
40 | public: |
41 | ~LevelData(); |
42 | |
43 | struct Element |
44 | { |
45 | int atom; // == -1 for walls |
46 | int x; |
47 | int y; |
48 | |
49 | Element() : atom(-1), x(-1), y(-1) {} |
50 | }; |
51 | |
52 | QList<Element> atomElements() const; |
53 | |
54 | bool containsWallAt(int x, int y) const; |
55 | |
56 | /** |
57 | * A pointer to molecule object that is the target of this level |
58 | */ |
59 | const Molecule* molecule() const; |
60 | |
61 | private: |
62 | friend class LevelSet; |
63 | |
64 | // @param elements contain atoms and walls. for walls 'atom' field will be -1 |
65 | // @param molecule - molecule to be solved. LevelData takes ownership of this object and will |
66 | // delete it |
67 | LevelData(const QList<Element>& elements, const Molecule* mol); |
68 | LevelData(const LevelData&); |
69 | |
70 | QList<Element> m_atoms; |
71 | bool m_field[FIELD_SIZE][FIELD_SIZE]; |
72 | |
73 | const Molecule* m_molecule; |
74 | }; |
75 | |
76 | /** |
77 | * Represents a set of levels. Implements loading of level set given its name |
78 | */ |
79 | class LevelSet |
80 | { |
81 | public: |
82 | LevelSet(); |
83 | ~LevelSet(); |
84 | |
85 | bool load(const QString& levelSetName); |
86 | bool loadFromFile(const QString& fileName); |
87 | |
88 | const LevelData* levelData(int levelNum) const; |
89 | |
90 | /** |
91 | * Returns name of the levelset. In general this name shouldn't be used in gui. |
92 | * To get the name suitable to showing in gui @see visibleName |
93 | */ |
94 | QString name() const; |
95 | |
96 | /** |
97 | * @return name of the levelset which is suitable for showing in gui |
98 | */ |
99 | QString visibleName() const; |
100 | |
101 | /** |
102 | * @return name of the author of the levelset |
103 | */ |
104 | QString author() const; |
105 | |
106 | /** |
107 | * @return email of the author of the levelset |
108 | */ |
109 | QString authorEmail() const; |
110 | |
111 | /** |
112 | * @return description of the levelset |
113 | */ |
114 | QString description() const; |
115 | |
116 | /** |
117 | * @return number of levels in this levelset |
118 | */ |
119 | int levelCount() const; |
120 | |
121 | /** |
122 | * Checks if default level set is installed on disk |
123 | */ |
124 | static bool isDefaultLevelsAvailable(); |
125 | |
126 | private: |
127 | void reset(); |
128 | const LevelData* readLevel(int levelNum) const; |
129 | const Molecule* readLevelMolecule(int levelNum) const; |
130 | |
131 | private: |
132 | KSharedConfigPtr m_levelsFile; |
133 | mutable QHash<int, LevelData*> m_levelCache; |
134 | |
135 | QString m_name; |
136 | QString m_visibleName; |
137 | QString m_description; |
138 | QString m_author; |
139 | QString m_authorEmail; |
140 | int m_levelCount; |
141 | }; |
142 | |
143 | #endif |
144 | |