forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11e650c
commit 432013e
Showing
1 changed file
with
68 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,72 @@ | ||
void setup() | ||
{ | ||
noLoop(); | ||
void setup() { | ||
size(300, 300); | ||
noLoop(); | ||
} | ||
void draw() | ||
{ | ||
//your code here | ||
|
||
void draw() { | ||
background(255); | ||
int total = 0; | ||
|
||
|
||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
|
||
Die die = new Die(50 + i * 60, 50 + j * 60); | ||
die.roll(); | ||
die.show(); | ||
total += die.value; | ||
} | ||
} | ||
|
||
|
||
fill(0); | ||
textSize(24); | ||
text("Total: " + total, 100, 250); | ||
} | ||
void mousePressed() | ||
{ | ||
redraw(); | ||
|
||
void mousePressed() { | ||
redraw(); | ||
} | ||
class Die //models one single dice cube | ||
{ | ||
//variable declarations here | ||
|
||
Die(int x, int y) //constructor | ||
{ | ||
//variable initializations here | ||
} | ||
void roll() | ||
{ | ||
//your code here | ||
} | ||
void show() | ||
{ | ||
//your code here | ||
} | ||
|
||
class Die { | ||
int x, y; | ||
int size; | ||
int value; | ||
|
||
|
||
Die(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
this.size = 50; | ||
roll(); | ||
} | ||
|
||
|
||
void roll() { | ||
value = (int)(Math.random() * 6) + 1; | ||
} | ||
|
||
|
||
void show() { | ||
fill(255); | ||
rect(x, y, size, size); | ||
|
||
|
||
fill(0); | ||
if (value == 1 || value == 3 || value == 5) { | ||
ellipse(x + size/2, y + size/2, 10, 10); | ||
} | ||
if (value >= 2) { | ||
ellipse(x + size/4, y + size/4, 10, 10); | ||
ellipse(x + 3*size/4, y + 3*size/4, 10, 10); | ||
} | ||
if (value >= 4) { | ||
ellipse(x + 3*size/4, y + size/4, 10, 10); | ||
ellipse(x + size/4, y + 3*size/4, 10, 10); | ||
} | ||
if (value == 6) { | ||
ellipse(x + size/4, y + size/2, 10, 10); | ||
ellipse(x + 3*size/4, y + size/2, 10, 10); | ||
} | ||
} | ||
} |