-
Notifications
You must be signed in to change notification settings - Fork 0
/
Candy.java
75 lines (58 loc) · 1.25 KB
/
Candy.java
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
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
/* lstting
* cis 120 f18
* hw 09
*/
public class Candy implements Comparable<Candy> {
private int score;
private int x;
private int y;
private boolean eaten;
private Image candy;
public Candy() {
int xTemp = (int) (39 * Math.random());
x = Model.SEGMENT_SIZE * (xTemp+1);
int yTemp = (int) (39 * Math.random());
y = Model.SEGMENT_SIZE * (yTemp+1);
score = (int) (2 * Math.random()) + 1; // pt range 1-3
eaten = false;
loadImage();
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setScore(int s) {
score = s;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getScore() {
return score;
}
public boolean getEaten() {
return eaten;
}
public void setEaten() {
eaten = true;
}
public void loadImage() {
ImageIcon c = new ImageIcon(this.getClass().getResource("/img/candy.png"));
candy = c.getImage();
}
public void draw(Graphics g, Model m) {
g.drawImage(candy, x, y, Model.SEGMENT_SIZE-1, Model.SEGMENT_SIZE-1, m);
}
@Override
public int compareTo(Candy o) {
return ((Integer) score).compareTo((Integer) o.getScore());
}
}