forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice.pde
112 lines (108 loc) · 2.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Die bob;
int d=0;
int total=0;
void mousePressed(){
total=0;
redraw();
}
void setup(){
size(600,600);
background(227,165,198);
bob = new Die(40,40);
noLoop();
}
void draw(){
fill(227,165,198);
noStroke();
rect(300,550,200,80);
for (int b=40; b<=500; b+=130){
for (int a=40; a<=500; a+=130){
bob = new Die(a,b);
bob.show();
bob.roll();
total=total+d;
}
}
textSize(28);
text("total dots: "+total,300,570);
}
class Die{
boolean one = false;
boolean two = false;
boolean three = false;
boolean four = false;
boolean five = false;
boolean six = false;
int myX, myY;
int num=(int)(Math.random()*6+1);
void roll(){
if (num == 1){
one=true;
d=1;
}else if (num==2){
two=true;
d=2;
}else if (num==3){
three=true;
d=3;
}else if (num==4){
four=true;
d=4;
}else if (num==5){
five=true;
d=5;
}else if (num==6){
six=true;
d=6;
}
}
void show(){
stroke(255,255,255);
strokeWeight(8);
fill(227,165,198);
rect(myX,myY,100,100);
fill(255,255,255);
noStroke();
if (one==true){
//one
ellipse(myX+50,myY+50,20,20);
}else if (two==true){
//two
ellipse(myX+30,myY+30,20,20);
ellipse(myX+70,myY+70,20,20);
}else if (three==true){
//three
ellipse(myX+20,myY+20,20,20);
ellipse(myX+50,myY+50,20,20);
ellipse(myX+80,myY+80,20,20);
}else if (four==true){
//four
ellipse(myX+20,myY+20,20,20);
ellipse(myX+80,myY+80,20,20);
ellipse(myX+20,myY+80,20,20);
ellipse(myX+80,myY+20,20,20);
}
else if (five==true){
//five
ellipse(myX+50,myY+50,20,20);
ellipse(myX+20,myY+20,20,20);
ellipse(myX+80,myY+80,20,20);
ellipse(myX+20,myY+80,20,20);
ellipse(myX+80,myY+20,20,20);
}
else if (six==true){
//six
ellipse(myX+30,myY+20,20,20);
ellipse(myX+70,myY+20,20,20);
ellipse(myX+30,myY+50,20,20);
ellipse(myX+70,myY+50,20,20);
ellipse(myX+30,myY+80,20,20);
ellipse(myX+70,myY+80,20,20);
}
}
Die(int x,int y){
roll();
myX = x;
myY = y;
}
}