jtge.util.random
Class Dice

java.lang.Object
  extended byjtge.util.random.Dice

public class Dice
extends java.lang.Object

Emulates a dice.

A dice is defined by :

Example : 2d8+3 stands for 2 dices of type 8 with a bonus of 3.

Version:
$Revision: 1.4 $ $Date: 2005/07/15 11:20:08 $
Author:
Jean-Laurent

Constructor Summary
Dice(int number, int type)
          Create a dice out of the number of dices and a type (e.g. no bonus).
Dice(int number, int type, int bonus)
          Create a dice out of the number of dices, the type and the bonus value.
Dice(java.lang.String definition)
          Create a dice from a textual definition.
 
Method Summary
 int roll()
          Roll the dice.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Dice

public Dice(int number,
            int type,
            int bonus)
Create a dice out of the number of dices, the type and the bonus value.

Number and type must be positive.

Parameters:
number - the number of rolls
type - the type of dice
bonus - the number added to the result

Dice

public Dice(int number,
            int type)
Create a dice out of the number of dices and a type (e.g. no bonus).

Number and type must be positive.

Parameters:
number - the number of rolls
type - the type of dice

Dice

public Dice(java.lang.String definition)
Create a dice from a textual definition.

The expected format is : {diceNumber}d{diceType}+{bonus}.

Parameters:
definition - the definition.
Method Detail

roll

public final int roll()
Roll the dice.

Returns:
the result

toString

public final java.lang.String toString()



Copyright © 2003-2005 . All Rights Reserved.