KDEGames

kgdifficulty.h
1 /***************************************************************************
2  * Copyright 2007 Nicolas Roffet <[email protected]> *
3  * Copyright 2007 Pino Toscano <[email protected]> *
4  * Copyright 2011-2012 Stefan Majewsky <[email protected]> *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU Library General Public License *
8  * version 2 as published by the Free Software Foundation *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU Library General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef KGDIFFICULTY_H
22 #define KGDIFFICULTY_H
23 
24 #include <QMetaType>
25 #include <QObject>
26 
27 #include <libkdegames_export.h>
28 
33 class KDEGAMES_EXPORT KgDifficultyLevel : public QObject
34 {
35  Q_OBJECT
37  Q_PROPERTY(bool default READ isDefault)
38  Q_PROPERTY(int hardness READ hardness)
39  Q_PROPERTY(QByteArray key READ key)
40  Q_PROPERTY(QString title READ title)
42  Q_PROPERTY(StandardLevel standardLevel READ standardLevel)
43  public:
45  {
46  Custom = -1,
47  RidiculouslyEasy = 10,
48  VeryEasy = 20,
49  Easy = 30,
50  Medium = 40,
51  Hard = 50,
52  VeryHard = 60,
53  ExtremelyHard = 70,
54  Impossible = 80
55  };
56 
58  KgDifficultyLevel(int hardness, const QByteArray& key, const QString& title, bool isDefault = false);
59  explicit KgDifficultyLevel(StandardLevel level, bool isDefault = false);
60  virtual ~KgDifficultyLevel();
61 
64  bool isDefault() const;
69  int hardness() const;
71  QByteArray key() const;
73  QString title() const;
76  StandardLevel standardLevel() const;
77  private:
78  class Private;
79  Private* const d;
80 };
81 
96 class KDEGAMES_EXPORT KgDifficulty : public QObject
97 {
98  Q_OBJECT
100  //Use currentLevel in game logic and selectedLevel in level selection UI.
101  Q_PROPERTY(const KgDifficultyLevel* currentLevel READ currentLevel WRITE select NOTIFY currentLevelChanged)
102  Q_PROPERTY(const KgDifficultyLevel* selectedLevel READ currentLevel WRITE select NOTIFY selectedLevelChanged)
103  Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged)
104  Q_PROPERTY(bool gameRunning READ isGameRunning WRITE setGameRunning NOTIFY gameRunningChanged)
105  public:
106  explicit KgDifficulty(QObject* parent = nullptr);
108  virtual ~KgDifficulty();
109 
112  void addLevel(KgDifficultyLevel* level);
114  void addStandardLevel(KgDifficultyLevel::StandardLevel level, bool isDefault = false);
124  void addStandardLevelRange(KgDifficultyLevel::StandardLevel from, KgDifficultyLevel::StandardLevel to);
128 
130  QList<const KgDifficultyLevel*> levels() const;
138  const KgDifficultyLevel* currentLevel() const;
139 
141  bool isEditable() const;
143  bool isGameRunning() const;
146  void setEditable(bool editable);
151  void setGameRunning(bool running);
152  Q_SIGNALS:
154  void editableChanged(bool editable);
156  void gameRunningChanged(bool gameRunning);
158  void currentLevelChanged(const KgDifficultyLevel* level);
162  void selectedLevelChanged(const KgDifficultyLevel* level);
163  public Q_SLOTS:
169  void select(const KgDifficultyLevel* level);
170  private:
171  class Private;
172  Private* const d;
173 };
174 
175 Q_DECLARE_METATYPE(const KgDifficultyLevel*)
176 
177 //TODO: Where to put documentation for this namespace?
178 namespace Kg
179 {
181  KDEGAMES_EXPORT KgDifficulty* difficulty();
183  KDEGAMES_EXPORT KgDifficultyLevel::StandardLevel difficultyLevel();
184 }
185 
186 class KXmlGuiWindow;
187 
188 //TODO KDE5: move this into a separate QtWidgets support library
189 namespace KgDifficultyGUI
190 {
195  KDEGAMES_EXPORT void init(KXmlGuiWindow* window, KgDifficulty* difficulty = nullptr);
196 }
197 
198 #endif // KGDIFFICULTY_H
Q_PROPERTY(...)
QCA_EXPORT void init()
Q_DISABLE_COPY(Class)
Q_ENUMS(...)
KgDifficulty manages difficulty levels of a game in a standard way.
Definition: kgdifficulty.h:96
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.