KGameDifficulty Class
KGameDifficulty manages difficulty levels of a game in a standard way. More...
| Header: | #include <KGameDifficulty> |
| Inherits: | QObject |
Properties
- currentLevel : const KGameDifficultyLevel*
- editable : bool
- gameRunning : bool
- selectedLevel : const KGameDifficultyLevel*
Public Functions
| virtual | ~KGameDifficulty() override |
| void | addLevel(KGameDifficultyLevel *level) |
| void | addStandardLevel(KGameDifficultyLevel::StandardLevel level, bool isDefault = false) |
| void | addStandardLevelRange(KGameDifficultyLevel::StandardLevel from, KGameDifficultyLevel::StandardLevel to) |
| void | addStandardLevelRange(KGameDifficultyLevel::StandardLevel from, KGameDifficultyLevel::StandardLevel to, KGameDifficultyLevel::StandardLevel defaultLevel) |
| const KGameDifficultyLevel * | currentLevel() const |
| bool | isEditable() const |
| bool | isGameRunning() const |
| QList<const KGameDifficultyLevel *> | levels() const |
| void | setEditable(bool editable) |
| void | setGameRunning(bool running) |
Public Slots
| void | select(const KGameDifficultyLevel *level) |
Signals
| void | currentLevelChanged(const KGameDifficultyLevel *level) |
| void | editableChanged(bool editable) |
| void | gameRunningChanged(bool gameRunning) |
| void | selectedLevelChanged(const KGameDifficultyLevel *level) |
Static Public Members
| KGameDifficulty * | global() |
| KGameDifficultyLevel::StandardLevel | globalLevel() |
Detailed Description
The difficulty can be a type of game (like in KMines: small or big field) or the AI skills (like in Bovo: how deep should the computer search to find the best move) or a combination of both of them. On the user point of view, it's not really different: either is the game easy or hard to play.
KGameDifficulty contains a list of KGameDifficultyLevel instances. One of these levels is selected; this selection will be recorded when the application is closed. A set of standard difficulty levels is provided by KGameDifficultyLevel, but custom levels can be defined at the same time.
Property Documentation
currentLevel : const KGameDifficultyLevel*
This property holds the current difficulty level.
After the KGameDifficulty object has been created, the current difficulty level will not be determined until currentLevel() is called for the first time. This allows the application developer to set up the difficulty levels before KGameDifficulty retrieves the last selected level from the configuration file.
Access functions:
| const KGameDifficultyLevel * | currentLevel() const |
| void | select(const KGameDifficultyLevel *level) |
Notifier signal:
| void | currentLevelChanged(const KGameDifficultyLevel *level) |
editable : bool
This property holds whether the difficulty level selection may be edited.
The default is true.
Access functions:
| bool | isEditable() const |
| void | setEditable(bool editable) |
Notifier signal:
| void | editableChanged(bool editable) |
gameRunning : bool
This property holds whether a game has been marked as running.
If a game is running and select() is called to select a new difficulty level, the user will be asked for confirmation.
Access functions:
| bool | isGameRunning() const |
| void | setGameRunning(bool running) |
Notifier signal:
| void | gameRunningChanged(bool gameRunning) |
selectedLevel : const KGameDifficultyLevel*
This property holds the selected level in the UI.
Access functions:
| const KGameDifficultyLevel * | currentLevel() const |
| void | select(const KGameDifficultyLevel *level) |
Notifier signal:
| void | selectedLevelChanged(const KGameDifficultyLevel *level) |
Member Function Documentation
[override virtual noexcept] KGameDifficulty::~KGameDifficulty()
Destroys this instance and all DifficultyLevel instances in it.
void KGameDifficulty::addLevel(KGameDifficultyLevel *level)
Adds the difficulty level level to this instance. This will not affect the currentLevel() if there is one.
void KGameDifficulty::addStandardLevel(KGameDifficultyLevel::StandardLevel level, bool isDefault = false)
A shortcut for addLevel(new KGameDifficultyLevel(level isDefault)).
void KGameDifficulty::addStandardLevelRange(KGameDifficultyLevel::StandardLevel from, KGameDifficultyLevel::StandardLevel to)
Adds a range of standard levels from from to to to this instance (including the boundaries). For example:
difficulty.addStandardLevelRange(
KGameDifficultyLevel::Easy,
KGameDifficultyLevel::VeryHard
);
This adds the levels "Easy", "Medium", "Hard" and "Very hard".
void KGameDifficulty::addStandardLevelRange(KGameDifficultyLevel::StandardLevel from, KGameDifficultyLevel::StandardLevel to, KGameDifficultyLevel::StandardLevel defaultLevel)
Adds a range of standard levels from from to to inclusive, with a default of defaultLevel.
This is an overloaded function.
[signal] void KGameDifficulty::currentLevelChanged(const KGameDifficultyLevel *level)
Emitted when a new difficulty level has been selected.
Note: Notifier signal for property currentLevel.
[static] KGameDifficulty *KGameDifficulty::global()
Returns a singleton instance of KGameDifficulty.
[static] KGameDifficultyLevel::StandardLevel KGameDifficulty::globalLevel()
Returns KGameDifficulty::global()->currentLevel()->standardLevel().
See also KGameDifficultyLevel::standardLevel.
QList<const KGameDifficultyLevel *> KGameDifficulty::levels() const
Returns a list of all difficulty levels, sorted by hardness.
[slot] void KGameDifficulty::select(const KGameDifficultyLevel *level)
Selects a new difficulty level. The given level must already have been added to this instance.
Note: This does nothing if isEditable() is false. If a game is running (according to setGameRunning()), the user will be asked for confirmation before the new difficulty level is selected.
Note: Setter function for properties currentLevel and selectedLevel.
[signal] void KGameDifficulty::selectedLevelChanged(const KGameDifficultyLevel *level)
Emitted after every call to select(), even when the user has rejected the change. This is useful to reset a difficulty level selection UI after a rejected change. level is the selected level.
Note: Notifier signal for property selectedLevel.