forked from APCSLowell/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDice.pde
66 lines (60 loc) · 1.25 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
int[][] positions = {
{20, 20},
{10, 20, 30, 20},
{20, 12, 10, 27, 30, 27},
{10, 10, 30, 10, 10, 30, 30, 30},
{10, 10, 30, 10, 10, 30, 30, 30, 20, 20},
{10, 10, 20, 10, 30, 10, 10, 30, 20, 30, 30, 30}
};
int total, currentRoll = 0;
void setup() {
size(540, 600);
noLoop();
}
void draw() {
background(76, 170, 84);
total = 0;
currentRoll = 0;
for (int x = 10; x < 520; x += 60) {
for (int y = 10; y < 500; y += 60) {
currentRoll += 1;
Die Roll = new Die(x, y);
Roll.roll();
Roll.show();
}
}
fill(250);
textSize(20);
fill(0);
text("Sum of dots: "+total, 190, 575);
}
void mousePressed() {
redraw();
}
class Die
{
int myRoll, myX, myY;
Die(int x, int y) //constructor
{
myX = x;
myY = y;
}
void roll()
{
myRoll = (int)(Math.random()*6)+1;
total += myRoll;
}
void show()
{
stroke(0);
fill(255);
rect(myX, myY, 40, 40, 5);
fill(0);
int[] currentPositions = positions[myRoll - 1];
for (int positionsIndex = 0; positionsIndex < currentPositions.length; positionsIndex += 2) {
int xPosition = currentPositions[positionsIndex];
int yPosition = currentPositions[positionsIndex + 1];
ellipse(myX + xPosition, myY + yPosition, 5, 5);
}
}
}