Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Public Member Functions | Related Functions | List of all members
gf::Dice Class Reference

A set of dice that can be rolled. More...

#include <gf/Dice.h>

Public Member Functions

constexpr Dice (int faces, int count=1, int modifier=0)
 Constructor. More...
 
constexpr Dice (StringRef str)
 Constructor. More...
 
constexpr int getFaces () const
 Get the number of faces. More...
 
constexpr int getCount () const
 Get the count of dice. More...
 
constexpr int getModifier () const
 Get the modifier. More...
 
int roll (gf::Random &random) const
 Roll the dice. More...
 

Related Functions

(Note that these are not member functions.)

constexpr gf::Dice operator"" _dice (const char *str, std::size_t sz)
 User defined operator for creating dice with common dice notation. More...
 
constexpr gf::Dice operator"" _d4 (unsigned long long int count)
 User defined operator for creating some d4. More...
 
constexpr gf::Dice operator"" _d6 (unsigned long long int count)
 User defined operator for creating some d6. More...
 
constexpr gf::Dice operator"" _d8 (unsigned long long int count)
 User defined operator for creating some d6. More...
 
constexpr gf::Dice operator"" _d10 (unsigned long long int count)
 User defined operator for creating some d10. More...
 
constexpr gf::Dice operator"" _d12 (unsigned long long int count)
 User defined operator for creating some d12. More...
 
constexpr gf::Dice operator"" _d20 (unsigned long long int count)
 User defined operator for creating some d20. More...
 
constexpr gf::Dice operator"" _d100 (unsigned long long int count)
 User defined operator for creating some d100. More...
 

Detailed Description

A set of dice that can be rolled.

The set of dice is composed of several dice with the same number of faces. After a roll a modifier can be added to the sum.

Constructor & Destructor Documentation

◆ Dice() [1/2]

constexpr gf::Dice::Dice ( int  faces,
int  count = 1,
int  modifier = 0 
)
inlineexplicit

Constructor.

With this constructor, you can set the number of faces, the count of dice and the modifier directly.

Parameters
facesThe number of faces of each dice
countThe count of dice
modifierThe modifier to apply after a roll

◆ Dice() [2/2]

constexpr gf::Dice::Dice ( StringRef  str)
inline

Constructor.

Parameters
strThe string representing a dice notation

Member Function Documentation

◆ getCount()

constexpr int gf::Dice::getCount ( ) const
inline

Get the count of dice.

Returns
The count of dice

◆ getFaces()

constexpr int gf::Dice::getFaces ( ) const
inline

Get the number of faces.

Returns
The number of faces

◆ getModifier()

constexpr int gf::Dice::getModifier ( ) const
inline

Get the modifier.

Returns
The modifier of the roll

◆ roll()

int gf::Dice::roll ( gf::Random random) const

Roll the dice.

Returns
The result of dice rolling

Friends And Related Function Documentation

◆ operator"" _d10()

constexpr gf::Dice operator"" _d10 ( unsigned long long int  count)
related

User defined operator for creating some d10.

See also
Dice notation - Wikipedia

◆ operator"" _d100()

constexpr gf::Dice operator"" _d100 ( unsigned long long int  count)
related

User defined operator for creating some d100.

See also
Dice notation - Wikipedia

◆ operator"" _d12()

constexpr gf::Dice operator"" _d12 ( unsigned long long int  count)
related

User defined operator for creating some d12.

See also
Dice notation - Wikipedia

◆ operator"" _d20()

constexpr gf::Dice operator"" _d20 ( unsigned long long int  count)
related

User defined operator for creating some d20.

See also
Dice notation - Wikipedia

◆ operator"" _d4()

constexpr gf::Dice operator"" _d4 ( unsigned long long int  count)
related

User defined operator for creating some d4.

See also
Dice notation - Wikipedia

◆ operator"" _d6()

constexpr gf::Dice operator"" _d6 ( unsigned long long int  count)
related

User defined operator for creating some d6.

See also
Dice notation - Wikipedia

◆ operator"" _d8()

constexpr gf::Dice operator"" _d8 ( unsigned long long int  count)
related

User defined operator for creating some d6.

See also
Dice notation - Wikipedia

◆ operator"" _dice()

constexpr gf::Dice operator"" _dice ( const char *  str,
std::size_t  sz 
)
related

User defined operator for creating dice with common dice notation.

The notation is the classical \( XdY+Z \) where \( X \) is the count of dice (1 if omitted), \( Y \) is the number of faces (mandatory), \( Z \) is the modifier (0 if omitted).

See also
Dice notation - Wikipedia