forked from divaclin/assign1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign1.pde
92 lines (70 loc) · 1.73 KB
/
assign1.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
SlotMachine machine;
boolean rolling = false;
// button information
boolean button = false;
int x = 640/2;
int y = 440;
int w = 150;
int h = 50;
// declare variables
// --------------------------------------------
// put your code inside here
int totalScore = 0;
// --------------------------------------------
void setup() {
size(640,480);
textFont(createFont("fonts/Square_One.ttf", 20));
machine = new SlotMachine();
}
void draw() {
background(245,229,124);
fill(64,162,171);
rect(320,248,396,154,25);
fill(253,253,253);
rect(220,247,97,114,2);
rect(320,247,97,114,2);
rect(420,247,97,114,2);
// draw button
fill(64,162,171);
noStroke();
rectMode(CENTER);
rect(x,y,w,h,105);
// show title
fill(64,64,63);
textAlign(CENTER, CENTER);
textSize(32);
text("Slot Machine",x,49);
textSize(20);
text("Score"+" "+":"+" "+totalScore,x, 89);
// event handler
if (button) {
if (!rolling){
rolling = true;
// start rolling
// -------------------------------------------------
// put your code inside here
// -------------------------------------------------
}
machine.roll();
textSize(19);
text("Stop",x,y);
} else {
if (rolling){
rolling = false;
// stop rolling
// -------------------------------------------------
// put your code inside here
// -------------------------------------------------
}
machine.stop();
fill(253,253,253);
textSize(19);
text("Roll",x,y);
}
}
// When the mouse is pressed, the state of the button is toggled.
void mousePressed() {
if (mouseX > x-w/2 && mouseX < x+w/2 && mouseY > y-h/2 && mouseY < y+h/2) {
button = !button;
}
}