-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snake.java
67 lines (54 loc) · 1.39 KB
/
Snake.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
package org.cis1200.snake;
import java.awt.*;
public class Snake extends GameObj {
public static final int SIZE = Background.SIZE;
private static int vx = SIZE;
private static int vy = 0;
private int x;
private int y;
private Color color;
private Color headColor;
private Color bodyColor;
private boolean tail;
public Snake(
int courtWidth, int courtHeight, int x, int y, int vx, int vy, Color color,
Color headColor, Color bodyColor, boolean tail
) {
super(vx, vy, x, y, SIZE, SIZE, courtWidth, courtHeight);
this.x = x;
this.y = y;
this.color = color;
this.headColor = headColor;
this.bodyColor = bodyColor;
this.tail = tail;
this.vx = vx;
this.vy = vy;
}
public Color getColor() {
return color;
}
public Color getHeadColor() {
return headColor;
}
public Color getBodyColor() {
return bodyColor;
}
public boolean getTail() {
return tail;
}
public void setTail(boolean tail) {
this.tail = tail;
}
@Override
public void draw(Graphics g) {
// draw each snake block
g.setColor(getColor());
g.fillRect(x, y, SIZE, SIZE);
}
@Override
public void move() {
if (getColor().equals(headColor)) {
color = bodyColor;
}
}
}