-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.java
68 lines (47 loc) · 1.19 KB
/
Object.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
import java.awt.Graphics;
public abstract class Object {
static final String DNA_SPLIT = "/";
private int xCoord, yCoord;
// An Object's position, expects int between 0 - 255;
Game game;
// The Game instance that encapsulates this Object.
public Object(Game game) {
this.game = game;
game.objectListAdd(this);
}
protected void setCoordinates(int x, int y) {
if (Game.validPos(x, y)) {
game.setEmpty(getXCoord(), getYCoord());
xCoord = x;
yCoord = y;
game.setObject(x, y, this);
}
}
protected int getXCoord() {
return xCoord;
}
protected int getYCoord() {
return yCoord;
}
protected void remove() {
game.setEmpty(xCoord, yCoord);
game.objectListRemove(this);
}
protected abstract void action();
protected abstract void paint(Graphics g);
protected static String intsToDNA(int[] args) {
String s = "" + args[0];
for (int i = 1; i < args.length; i++) {
s += Part.DNA_SPLIT + args[i];
}
return s;
}
protected static int[] DNAtoInts(String DNA) {
String[] strands = DNA.split(DNA_SPLIT);
int[] ints = new int[strands.length];
for (int i = 0; i < strands.length; i++) {
ints[i] = Integer.parseInt(strands[i]);
}
return ints;
}
}