#include <kgamedifficulty.h>

Public Types | |
| enum | onChange { RestartOnChange, NoRestartOnChange } |
| enum | standardLevel { RidiculouslyEasy = 10, VeryEasy = 20, Easy = 30, Medium = 40, Hard = 50, VeryHard = 60, ExtremelyHard = 70, Impossible = 80, Configurable = 90, Custom = 100, NoLevel = 110 } |
Public Member Functions | |
| virtual | ~KGameDifficulty () |
Static Public Member Functions | |
| static void | init (KXmlGuiWindow *window, const QObject *recvr, const char *slotStandard, const char *slotCustom=0) |
| static void | setRestartOnChange (onChange restart) |
| static void | addStandardLevel (standardLevel level) |
| static void | removeStandardLevel (standardLevel level) |
| static void | addCustomLevel (int key, const QString &appellation) |
| static void | removeCustomLevel (int key) |
| static void | setEnabled (bool enabled) |
| static void | setLevel (standardLevel level) |
| static standardLevel | level () |
| static QString | levelString () |
| |
| static void | setLevelCustom (int key) |
| static int | levelCustom () |
| static void | setRunning (bool running) |
Friends | |
| class | KGameDifficultyPrivate |
KGameDifficulty provides standard actions on the main menu and a standard combo box in the status bar with the list of the difficulty levels. They both use the standard icon for "difficulty". Using KGameDifficulty instead of a custom implementation is better to provide a uniform user experience over all KDE games.
It is possible to use standard difficulty levels (like "Easy", "Hard", ...) or define custom ones ("My level!"...). Using standard levels reduces the work of the translator teams and assures that the translation (for instance of "Medium") will not be different in different games (and it is better because it is uniform). In some games, it is not problem if the player changes the difficulty level during a running game. In other, it is: the current game should be given up and a new game should be started. In this case, KGameDifficulty provides a confirmation dialog so the game programmer does not have to manage this himself: he just have to tell KGameDifficulty when the game is running and when not.
Code example: definition of the difficulty levels in the main window class.
KGameDifficulty::init(this, this, SLOT(levelChanged(KGameDifficulty::standardLevel))); KGameDifficulty::addStandardLevel(KGameDifficulty::Easy); KGameDifficulty::addStandardLevel(KGameDifficulty::Medium); KGameDifficulty::addStandardLevel(KGameDifficulty::Hard); KGameDifficulty::setRestartOnChange(KGameDifficulty::NoRestartOnChange); // The default level (it should be read from the config file). KGameDifficulty::setLevel(KGameDifficulty::Medium); // And you need also to define the slot "levelChanged" to manage changes. // ...
Note that this class is a singleton. So you can have only one current difficulty level per application.
Definition at line 74 of file kgamedifficulty.h.
Behavior on change Does the game have to be restarted, when the player changes the difficulty level? In this case and if the game is running, a confirmation dialog is displayed and the player can cancel the change.
| RestartOnChange | |
| NoRestartOnChange |
The current game has to be canceled and a new game will be started on change.
The current game can continue on change. |
Definition at line 82 of file kgamedifficulty.h.
Standard difficulty levels If they fit the needs of the game, the standard appellations of the difficulty levels should be used.
Definition at line 92 of file kgamedifficulty.h.
| KGameDifficulty::~KGameDifficulty | ( | ) | [virtual] |
Destructor
Definition at line 285 of file kgamedifficulty.cpp.
| void KGameDifficulty::init | ( | KXmlGuiWindow * | window, | |
| const QObject * | recvr, | |||
| const char * | slotStandard, | |||
| const char * | slotCustom = 0 | |||
| ) | [static] |
Initialize the difficulty class You must call this class before using the singleton.
| window | The window where to add menu items. | |
| recvr | Object that receives the signals and have the following slots. | |
| slotStandard | Slot to call when the player changed the difficulty level to a standard one. Slot should have the signature like: SLOT(levelChanged(KGameDifficulty::standardLevel)) | |
| slotCustom | Slot to call when the player changed the difficulty level to a custom one. (Optional). Slot should have the signature like: SLOT(customLevelChanged(int)) |
Definition at line 291 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::init().

| void KGameDifficulty::setRestartOnChange | ( | onChange | restart | ) | [static] |
Set if a new game has to be started by change Default is RestartOnChange.
| restart | Behavior on change |
Definition at line 297 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_comboBox, KGameDifficultyPrivate::m_restartOnChange, and RestartOnChange.
Referenced by KGameDifficultyPrivate::init().
| void KGameDifficulty::addStandardLevel | ( | standardLevel | level | ) | [static] |
Add a standard difficulty level You should add all the standard difficulty levels you need after the initialization of the class. Standard difficulty levels are displayed before custom levels (if available).
| level | Standard difficulty level to add |
Definition at line 310 of file kgamedifficulty.cpp.
References Custom, KGameDifficultyPrivate::m_standardLevels, NoLevel, and KGameDifficultyPrivate::rebuildActions().

| void KGameDifficulty::removeStandardLevel | ( | standardLevel | level | ) | [static] |
Remove a standard difficulty level
| level | Standard difficulty level to remove |
Definition at line 321 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_standardLevels, and KGameDifficultyPrivate::rebuildActions().

| void KGameDifficulty::addCustomLevel | ( | int | key, | |
| const QString & | appellation | |||
| ) | [static] |
Add a custom difficulty level If you need custom appellations like "8x8", "Coward", "Courageous", "Tired of life" or whatever, you can define them with this method. Custom difficulty levels are displayed after standard levels (if available).
| key | Custom level identifier. (It must be distinct for every different level. Trying to add a new level with an allocated key replace the previous level.). | |
| appellation | Custom level appellation. |
Definition at line 330 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_customLevels, and KGameDifficultyPrivate::rebuildActions().

| void KGameDifficulty::removeCustomLevel | ( | int | key | ) | [static] |
Remove a custom difficulty level
| key | Custom level identifier. |
Definition at line 339 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_customLevels, and KGameDifficultyPrivate::rebuildActions().

| void KGameDifficulty::setEnabled | ( | bool | enabled | ) | [static] |
Set if the difficulty level may be changed.
If not, all the actions are disabled. Default is "true".
| enabled | State. |
Definition at line 348 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_comboBox, and KGameDifficultyPrivate::m_menu.
| void KGameDifficulty::setLevel | ( | standardLevel | level | ) | [static] |
Set the new current difficulty level as a standard one
| level | Standard level. |
Definition at line 358 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::setLevel().
Referenced by KGameDifficultyPrivate::rebuildActions().

| KGameDifficulty::standardLevel KGameDifficulty::level | ( | ) | [static] |
Get the current standard difficulty level
Definition at line 382 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_level.
| QString KGameDifficulty::levelString | ( | ) | [static] |
Definition at line 390 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::standardLevelString().

| void KGameDifficulty::setLevelCustom | ( | int | key | ) | [static] |
Set the new current difficulty level as a custom one This sets also the value of the standard level to "custom".
| key | Custom level identifier. |
Definition at line 366 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::setLevelCustom().
Referenced by KGameDifficultyPrivate::rebuildActions().

| int KGameDifficulty::levelCustom | ( | ) | [static] |
Get the current custom difficulty level It does only make sense to get the current custom difficulty level, if the value of the level is "custom".
Definition at line 374 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_levelCustom.
| void KGameDifficulty::setRunning | ( | bool | running | ) | [static] |
Set the game state: Running or not The game state should be defined if the current onChange value is restartByChange. Default: false.
| running | Running state. |
Definition at line 398 of file kgamedifficulty.cpp.
References KGameDifficultyPrivate::m_running.
friend class KGameDifficultyPrivate [friend] |
Definition at line 231 of file kgamedifficulty.h.
1.5.3