Due: Thursday 10/24 10:00am

Submission name: w17_dice

dice

Write the Die class for a processing program. The code for the Ball class can be found on thesource under bounceObject. It will be useful as a reference. For this assignment, use the following driver file code:

Die d0, d1;

void setup() {
  size(200, 200);
  d0 = new Die(25, height/2 - 25, 50);
  d1 = new Die(125, height/2 - 25, 50);
}//setup

void draw() {
  background(150);

  d0.display();
  d1.display();
}//draw


void keyPressed() {
  if (key == ' ') {
    d0.roll();
    d1.roll();
  }//roll
}//if keyPressed

Die Class Components:

Fields:

  • You will need fields for the position, size and value of the die.
  • You may want to add other fields to enhance the visual presentation of the die, but this is not necessary.

Constructor:

  • Takes 3 arguments representing the (x, y) position and size of the Die.
  • Sets the value to a random integer in the range [1, 6].

Methods:

  • void display()
    • Draws the die as a square with the value printed inside the die as text. Use the image above as your guide.
  • void roll()
    • Sets the value of the die to a new integer in the range [1, 6]

Optional Additions

If you get all this working, here are some things you could try:

  • Add the capability to modify the number of sides a Die could have.
  • Instead of displaying a number, display “pips” (the little circles on a standard die).
  • Other visual flair.