KGameDifficulty

Search for usage in LXR

#include <KGameDifficulty>

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 addCustomLevel (int key, const QString &appellation)
 
static void addStandardLevel (standardLevel level)
 
static void init (KXmlGuiWindow *window, const QObject *recvr, const char *slotStandard, const char *slotCustom=nullptr)
 
static standardLevel level ()
 
static int levelCustom ()
 
static QString levelString ()
 
static QMap< int, QByteArraylevelWeights ()
 
static QPair< QByteArray, QStringlocalizedLevelString ()
 
static QMap< QByteArray, QStringlocalizedLevelStrings ()
 
static void removeCustomLevel (int key)
 
static void removeStandardLevel (standardLevel level)
 
static void setEnabled (bool enabled)
 
static void setLevel (standardLevel level)
 
static void setLevelCustom (int key)
 
static void setRestartOnChange (onChange restart)
 
static void setRunning (bool running)
 

Detailed Description

KGameDifficuty manages the game difficulty levels in a standard way.

KGameDifficulty manages the difficulty levels of a game. The difficulty can be a type of game (like in KMines: small field / 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 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 no problem if the player changes the difficulty level during a running game. In others, 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 has to tell KGameDifficulty when the game is running and when not.

Code example: definition of the difficulty levels in the main window class.

Note that this class is a singleton. So you can have only one current difficulty level per application.

Author
Nicolas Roffet, nicol.nosp@m.as-k.nosp@m.de@ro.nosp@m.ffet.nosp@m..com
Deprecated:
Since 4.9, use KgDifficulty instead.

Definition at line 75 of file kgamedifficulty.h.

Member Enumeration Documentation

◆ onChange

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.

Enumerator
RestartOnChange 

The current game has to be canceled and a new game will be started on change.

NoRestartOnChange 

The current game can continue on change.

Definition at line 84 of file kgamedifficulty.h.

◆ standardLevel

Standard difficulty levels.

If they fit the needs of the game, the standard appellations of the difficulty levels should be used.

Enumerator
RidiculouslyEasy 

Level "Ridiculously easy".

VeryEasy 

Level "Very easy".

Easy 

Level "Easy".

Medium 

Level "Medium".

Hard 

Level "Hard".

VeryHard 

Level "Very hard".

ExtremelyHard 

Level "Extremely hard".

Impossible 

Level "Impossible"

Configurable 

Level "Custom".

This is a special item to let the player configure the difficulty level. The configuration of the user level has to be implemented in each game using it with an adapted dialog. Example: In a minesweeper game like KMines, the player wants to define the number of rows, columns and mines.

Custom 

Any custom appellations for levels.

NoLevel 

No level.

Definition at line 94 of file kgamedifficulty.h.

Constructor & Destructor Documentation

◆ ~KGameDifficulty()

KGameDifficulty::~KGameDifficulty ( )
virtual

Destructor.

Definition at line 272 of file kgamedifficulty.cpp.

Member Function Documentation

◆ addCustomLevel()

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).

Parameters
keyCustom level identifier. (It must be distinct for every different level. Trying to add a new level with an allocated key replace the previous level.).
appellationCustom level appellation.

Definition at line 313 of file kgamedifficulty.cpp.

◆ addStandardLevel()

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).

Parameters
levelStandard difficulty level to add

Definition at line 295 of file kgamedifficulty.cpp.

◆ init()

void KGameDifficulty::init ( KXmlGuiWindow window,
const QObject recvr,
const char *  slotStandard,
const char *  slotCustom = nullptr 
)
static

Initialize the difficulty class.

You must call this class before using the singleton.

Parameters
windowThe window where to add menu items.
recvrObject that receives the signals and have the following slots.
slotStandardSlot to call when the player changed the difficulty level to a standard one. Slot should have the signature like: SLOT(levelChanged(KGameDifficulty::standardLevel))
slotCustomSlot 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 277 of file kgamedifficulty.cpp.

◆ level()

KGameDifficulty::standardLevel KGameDifficulty::level ( )
static

Get the current standard difficulty level.

Returns
The current standard level, or customLevel if a custom level is selected, or noLevel if no difficulty level is selected.

Definition at line 360 of file kgamedifficulty.cpp.

◆ levelCustom()

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".

Returns
The current custom level identifier.

Definition at line 353 of file kgamedifficulty.cpp.

◆ levelString()

QString KGameDifficulty::levelString ( )
static
Returns
current standard level string name

Definition at line 367 of file kgamedifficulty.cpp.

◆ levelWeights()

QMap< int, QByteArray > KGameDifficulty::levelWeights ( )
static
Returns
map with the weight order of untranslated standard level names matches value of standardLevel enum
Since
KDE 4.2

Definition at line 399 of file kgamedifficulty.cpp.

◆ localizedLevelString()

QPair< QByteArray, QString > KGameDifficulty::localizedLevelString ( )
static
Returns
current standard level name translated string

Definition at line 374 of file kgamedifficulty.cpp.

◆ localizedLevelStrings()

QMap< QByteArray, QString > KGameDifficulty::localizedLevelStrings ( )
static
Returns
list of translated standard level string names

Definition at line 381 of file kgamedifficulty.cpp.

◆ removeCustomLevel()

void KGameDifficulty::removeCustomLevel ( int  key)
static

Remove a custom difficulty level.

Parameters
keyCustom level identifier.

Definition at line 321 of file kgamedifficulty.cpp.

◆ removeStandardLevel()

void KGameDifficulty::removeStandardLevel ( standardLevel  level)
static

Remove a standard difficulty level.

Parameters
levelStandard difficulty level to remove

Definition at line 305 of file kgamedifficulty.cpp.

◆ setEnabled()

void KGameDifficulty::setEnabled ( bool  enabled)
static

Set if the difficulty level may be changed.

If not, all the actions are disabled. Default is "true".

Parameters
enabledState.

Definition at line 329 of file kgamedifficulty.cpp.

◆ setLevel()

void KGameDifficulty::setLevel ( standardLevel  level)
static

Set the new current difficulty level as a standard one.

Parameters
levelStandard level.

Definition at line 339 of file kgamedifficulty.cpp.

◆ setLevelCustom()

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".

Parameters
keyCustom level identifier.

Definition at line 346 of file kgamedifficulty.cpp.

◆ setRestartOnChange()

void KGameDifficulty::setRestartOnChange ( onChange  restart)
static

Set if a new game has to be started by change.

Default is RestartOnChange.

Parameters
restartBehavior on change

Definition at line 282 of file kgamedifficulty.cpp.

◆ setRunning()

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.

Parameters
runningRunning state.

Definition at line 416 of file kgamedifficulty.cpp.


The documentation for this class was generated from the following files:
static void init(KXmlGuiWindow *window, const QObject *recvr, const char *slotStandard, const char *slotCustom=nullptr)
Initialize the difficulty class.
static void addStandardLevel(standardLevel level)
Add a standard difficulty level.
@ Hard
Level "Hard".
@ Easy
Level "Easy".
standardLevel
Standard difficulty levels.
@ Medium
Level "Medium".
@ NoRestartOnChange
The current game can continue on change.
static void setRestartOnChange(onChange restart)
Set if a new game has to be started by change.
static void setLevel(standardLevel level)
Set the new current difficulty level as a standard one.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:47:36 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.