-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFood.java
61 lines (48 loc) · 1.03 KB
/
Food.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
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class Food extends Object {
private static final int DEFAULT_AMOUNT = 100;
int amount = DEFAULT_AMOUNT;
Plant plant;
Color color;
public Food(Game game, Plant p) {
super(game);
plant = p;
color = plant.leafColor;
}
public Food(Game game, int x, int y, Plant p) {
super(game);
setCoordinates(x, y);
plant = p;
color = plant.leafColor;
}
public Food(Game game, int x, int y, int amount, Plant p) {
super(game);
setCoordinates(x, y);
this.amount = amount;
plant = p;
color = plant.leafColor;
}
@Override
protected void action() {
if(plant.life == 0){
remove();
}
}
protected int getAmount() {
return amount;
}
protected Waste getWaste(){
return new WasteSeed(game, plant.DNA);
}
protected void remove(){
super.remove();
}
@Override
protected void paint(Graphics g) {
g.setColor(color);
g.fillRect(getXCoord() * game.zoomLevel, getYCoord() * game.zoomLevel,
game.zoomLevel, game.zoomLevel);
}
}