Class Dice

java.lang.Object
com.takenoko.weather.Dice
Direct Known Subclasses:
WeatherDice

public class Dice extends Object
Dice with N sides, by default it has 6.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
    private final Random
     
    private final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Dice(int sides)
    Specify the number of sides
    Dice(int sides, Random random)
    Specify the number of sides and the Random Generator
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
     
    protected int
     
    protected int
    Roll the dice

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • random

      private final Random random
    • sides

      private final int sides
    • lastRoll

      private int lastRoll
  • Constructor Details

    • Dice

      public Dice(int sides, Random random)
      Specify the number of sides and the Random Generator
      Parameters:
      sides - number of sides of the dice
      random - random number generator
    • Dice

      public Dice(int sides)
      Specify the number of sides
      Parameters:
      sides - number of sides of the dice
  • Method Details

    • roll

      protected int roll()
      Roll the dice
      Returns:
      the result of the roll (between 0 and N-1)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • peek

      protected int peek()