Advertisement
Guest User

Untitled

a guest
Apr 5th, 2012
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. public class PairOfDice
  2. {
  3.    protected Die d1, d2;
  4.    private int value1, value2, total;
  5.  
  6.    //-----------------------------------------------------------------
  7.    //  Creates two six-sided Die objects, both with an initial
  8.    //  face value of one.
  9.    //-----------------------------------------------------------------
  10.    public PairOfDice ()
  11.    {
  12.       d1 = new Die();
  13.       d2 = new Die();
  14.       value1 = 1;
  15.       value2 = 1;
  16.       total = value1 + value2;
  17.    }
  18.  
  19.    //-----------------------------------------------------------------
  20.    //  Rolls both dice and returns the combined result.
  21.    //-----------------------------------------------------------------
  22.    public void roll ()
  23.    {
  24.        d1.roll();
  25.        d2.roll();
  26.    }
  27.  
  28.    //-----------------------------------------------------------------
  29.    //  Returns the current combined dice total.
  30.    //-----------------------------------------------------------------
  31.    public int getDiceSum ()
  32.    {
  33.        total = getDie1() + getDie2();
  34.       return total;
  35.    }
  36.  
  37.    //-----------------------------------------------------------------
  38.    //  Returns the current value of the first die.
  39.    //-----------------------------------------------------------------
  40.    public int getDie1 ()
  41.    {
  42.       return d1.getFaceValue();
  43.    }
  44.  
  45.    //-----------------------------------------------------------------
  46.    //  Returns the current value of the second die.
  47.    //-----------------------------------------------------------------
  48.    public int getDie2 ()
  49.    {
  50.       return d2.getFaceValue();
  51.    }
  52.    
  53.     //-----------------------------------------------------------------
  54.    //  Sets the FaceValue of the first die.
  55.    //-----------------------------------------------------------------
  56.     public void setDie1 (int value)
  57.     {
  58.         d1.setFaceValue(value);
  59.     }
  60.    
  61.     //-----------------------------------------------------------------
  62.    //  Sets the FaceValue of the second die.
  63.    //-----------------------------------------------------------------
  64.     public void setDie2(int value)
  65.     {
  66.         d2.setFaceValue(value);
  67.     }
  68.    
  69.     //-----------------------------------------------------------------
  70.    //  Sets the FaceValue of the second die.
  71.    //-----------------------------------------------------------------
  72.     public String toString()
  73.    {
  74.     String result = "You rolled a " + total;
  75.  
  76.     return result;
  77.    }
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement