com.huyderman.javadice
Class Die

java.lang.Object
  extended by com.huyderman.javadice.Die
Direct Known Subclasses:
DieNN, DieOpenEnded

public class Die
extends java.lang.Object

The Die object defines a die or dice. It contains information about size of die, number of dice, and any other bonuses. It also contains methods to change the die, such as converting to another type of dice, or optimizing number of dice.

Version:
1.2
Author:
Jo-Herman Haugholt

Field Summary
protected  java.util.Random r
           
 
Constructor Summary
Die()
          Constructs a six-sided Die
Die(double average, int diesize)
          Constructs a Die based on the average result.
Die(double average, int diesize, java.util.Random r)
          Constructs a Die based on the average result.
Die(int sides)
          Constructs a Die with the specified number of sides.
Die(int dieSides, double diesize)
          Constructs a die where the number of dice is given as a double, and assigns appropriate bonuses.
Die(int dieSides, double diesize, java.util.Random r)
          Constructs a die where the number of dice is given as a double, and assigns appropriate bonuses.
Die(int number, int sides, int bonus)
          Constructs a Die with the specified number of sides and a bonus.
Die(int number, int sides, int bonus, java.util.Random r)
          Constructs a Die with the specified number of sides and a bonus.
Die(int sides, java.util.Random r)
          Constructs a Die with the specified number of sides.
Die(java.lang.String s)
          Constructs from a string. the format of the string must be "[x]Dy[(+|-)z]", where x is number of dice, y is diesize, and z is bonus.
Die(java.lang.String s, java.util.Random r)
          Constructs from a string. the format of the string must be in the following regular expression: "([0-9])*D([0-9])+([\+\-][0-9]*)?"
 
Method Summary
 double average()
          Returns the average result of rolling this die
 boolean equals(java.lang.Object obj)
           
 int getBonusToDice()
           
 int getNumberOfDice()
           
 int getSidesOnDie()
           
 int hashCode()
           
 int max()
           
 int min()
           
 void revaluate()
          Revaluates die, adding/removing dice to limit die bonuses.
 int roll()
          Rolls the die
 void setBonusToDice(int bonusToDice)
           
 void setNumberOfDice(int numberOfDice)
           
 void setRandom(long seed)
          Sets a seed for this dice assosiated DiceRoller
 void setRandom(java.util.Random r)
          Sets a Random object for this dice assosiated DiceRoller
 void setSidesOnDie(int sidesOnDie)
           
 double stdev()
          Returns the standard deviation of the die
 java.lang.String toString()
          Makes a String representation of the die, in the form of 'xDn+y'
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

r

protected java.util.Random r
Constructor Detail

Die

public Die()
Constructs a six-sided Die


Die

public Die(double average,
           int diesize)
Constructs a Die based on the average result.

Parameters:
average - average value to convert to dice
diesize - size of dice

Die

public Die(double average,
           int diesize,
           java.util.Random r)
Constructs a Die based on the average result.

Parameters:
average - average value to convert to dice
diesize - size of dice
r - TODO

Die

public Die(int sides)
Constructs a Die with the specified number of sides.

Parameters:
sides - The number of sides on die.

Die

public Die(int sides,
           java.util.Random r)
Constructs a Die with the specified number of sides.

Parameters:
sides - The number of sides on die.
r - TODO

Die

public Die(int dieSides,
           double diesize)
Constructs a die where the number of dice is given as a double, and assigns appropriate bonuses.

Parameters:
dieSides - Number of sides on Die
diesize - Double representation of number of dice
See Also:
com.huyderman.javadice

Die

public Die(int dieSides,
           double diesize,
           java.util.Random r)
Constructs a die where the number of dice is given as a double, and assigns appropriate bonuses.

Parameters:
dieSides - Number of sides on Die
diesize - Double representation of number of dice
r - TODO
See Also:
com.huyderman.javadice

Die

public Die(int number,
           int sides,
           int bonus)
Constructs a Die with the specified number of sides and a bonus.

Parameters:
number - Number of Dice
sides - Number of sides on die
bonus - Bonus to dice

Die

public Die(int number,
           int sides,
           int bonus,
           java.util.Random r)
Constructs a Die with the specified number of sides and a bonus.

Parameters:
number - Number of Dice
sides - Number of sides on die
bonus - Bonus to dice
r - TODO

Die

public Die(java.lang.String s)
Constructs from a string. the format of the string must be "[x]Dy[(+|-)z]", where x is number of dice, y is diesize, and z is bonus.

Parameters:
s - string to parse

Die

public Die(java.lang.String s,
           java.util.Random r)
Constructs from a string. the format of the string must be in the following regular expression: "([0-9])*D([0-9])+([\+\-][0-9]*)?" \1 is number of dice \2 is size of dice \3 is bonus or penalty

Parameters:
s - string to parse
r - TODO
Method Detail

average

public double average()
Returns the average result of rolling this die

Returns:
average result

stdev

public double stdev()
Returns the standard deviation of the die

Returns:
standard deviation

revaluate

public void revaluate()
Revaluates die, adding/removing dice to limit die bonuses.


roll

public int roll()
Rolls the die

Returns:
result of rolling the die

toString

public java.lang.String toString()
Makes a String representation of the die, in the form of 'xDn+y'

Overrides:
toString in class java.lang.Object
Returns:
Returns String representation of die

setRandom

public void setRandom(long seed)
Sets a seed for this dice assosiated DiceRoller

Parameters:
seed - random seed

setRandom

public void setRandom(java.util.Random r)
Sets a Random object for this dice assosiated DiceRoller

Parameters:
r - random object

max

public int max()
Returns:
the maximum value of die

min

public int min()
Returns:
the minimum value of die

getBonusToDice

public int getBonusToDice()
Returns:
Returns the bonusToDice.

setBonusToDice

public void setBonusToDice(int bonusToDice)
Parameters:
bonusToDice - The bonusToDice to set.

getNumberOfDice

public int getNumberOfDice()
Returns:
Returns the numberOfDice.

setNumberOfDice

public void setNumberOfDice(int numberOfDice)
Parameters:
numberOfDice - The numberOfDice to set.

getSidesOnDie

public int getSidesOnDie()
Returns:
Returns the sidesOnDie.

setSidesOnDie

public void setSidesOnDie(int sidesOnDie)
Parameters:
sidesOnDie - The sidesOnDie to set.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


Copyright © 2002-2009 Huyderman Studios. All Rights Reserved.