forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDice.pde
More file actions
68 lines (67 loc) · 1.83 KB
/
Dice.pde
File metadata and controls
68 lines (67 loc) · 1.83 KB
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
void setup()
{
noLoop();
size(500,500);
}
void draw()
{
background(255,0,0);
int sum = 0;
for(int x = 0; x < 460; x += 50 ){
for(int y = 0; y < 450; y += 50){
int num = ((int)(Math.random()*6))+1;
sum = sum + num;
Die wilburLiu = new Die(x,y,num);
wilburLiu.show();
}
}
textSize(24);
text("sum : " + sum, 250 ,475);
}
void mousePressed()
{
redraw();
}
class Die //models one single dice cube
{
int inX, inY, inNum;
Die(int x, int y, int num) //constructor
{
inX = x;
inY = y;
inNum = num;
}
void roll()
{
//your code here
}
void show()
{
int diceSize = 50;
fill(255);
rect(inX, inY, 50, 50, 10);
if(inNum%2==1){
fill(0);
ellipse((float)(inX + diceSize/2), (float)(inY + diceSize/2), (float)(diceSize/6), (float)(diceSize/6));
noFill();
}
if(inNum>=2){
fill(0);
ellipse((float)(inX + diceSize - diceSize/6), (float)(inY + diceSize - diceSize/6), (float)(diceSize/6), (float)(diceSize/6));
ellipse((float)(inX + diceSize/6), (float)(inY + diceSize/6), (float)(diceSize/6), (float)(diceSize/6));
noFill();
}
if(inNum>=4){
fill(0);
ellipse((float)(inX + diceSize - diceSize/6), (float)(inY + diceSize/6), (float)(diceSize/6), (float)(diceSize/6));
ellipse((float)(inX + diceSize/6), (float)(inY + diceSize - diceSize/6), (float)(diceSize/6), (float)(diceSize/6));
noFill();
}
if(inNum==6){
fill(0);
ellipse((float)(inX + diceSize - diceSize/6), (float)(inY + diceSize/2), (float)(diceSize/6), (float)(diceSize/6));
ellipse((float)(inX + diceSize/6), (float)(inY + diceSize/2), (float)(diceSize/6), (float)(diceSize/6));
noFill();
}
}
}