forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice.pde
83 lines (82 loc) · 2.15 KB
/
Dice.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
int sumCount = 0;
void setup()
{
background(#5175DE);
size(500,500);
noLoop();
}
void draw()
{
for( int myY = 20; myY<=400; myY+=50){
for (int myX = 30; myX<=450; myX+=50){
Die bob = new Die(myX, myY);
bob.show();
bob.roll();
}
}
}
void mousePressed()
{
sumCount = 0;
redraw();
}
class Die //models one single dice cube
{
int myX, myY, diceNumber;
Die(int x, int y) //constructor
{
myX = x;
myY = y;
roll();
}
void roll()
{
diceNumber = (int)(Math.random()*6) + 1;
}
void show()
{
stroke(0);
sumCount = sumCount + diceNumber;
fill(255);
rect(myX, myY, 40, 40, 5);
fill((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256) );
if (diceNumber == 1){
ellipse(myX+20, myY+20, 5, 5);
}
else if (diceNumber == 2){
ellipse(myX+30, myY+10, 5, 5);
ellipse(myX+10, myY+30, 5, 5);
}
else if(diceNumber == 3){
ellipse(myX+30, myY+10, 5, 5);
ellipse(myX+20, myY+20, 5, 5);
ellipse(myX+10, myY+30, 5, 5);
}
else if (diceNumber == 4){
ellipse(myX+10, myY+10, 5, 5);
ellipse(myX+10, myY+30, 5, 5);
ellipse(myX+30, myY+10, 5, 5);
ellipse(myX+30, myY+30, 5, 5);
}
else if (diceNumber == 5){
ellipse(myX+20, myY+20, 5, 5);
ellipse(myX+10, myY+10, 5, 5);
ellipse(myX+10, myY+30, 5, 5);
ellipse(myX+30, myY+10, 5, 5);
ellipse(myX+30, myY+30, 5, 5);
}
else {
ellipse(myX+10, myY+10, 5, 5);
ellipse(myX+10, myY+20, 5, 5);
ellipse(myX+10, myY+30, 5, 5);
ellipse(myX+30, myY+10, 5, 5);
ellipse(myX+30, myY+20, 5, 5);
ellipse(myX+30, myY+30, 5, 5);
}
fill(#5175DE);
noStroke();
rect(200, 460, 90, 20);
fill(255);
text("The Sum Is: " + sumCount, 200, 470);
}
}