-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlant.java
More file actions
51 lines (43 loc) · 1.03 KB
/
Plant.java
File metadata and controls
51 lines (43 loc) · 1.03 KB
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
import java.util.List;
import javafx.scene.paint.Color;
/**
* Plant.
* @author Kexin Wang
* @time 2025.02.21
* @version 1.0
*/
public class Plant
{
private boolean alive;
private Field field;
private Location location;
private static final Color PLANT_COLOR = Color.rgb(77,219,35);
/**
* Create a new plant at location in field.
* @param field The field currently occupied.
* @param location The location within the field.
*/
public Plant(Field field, Location location) {
this.alive = true;
this.field = field;
this.location = location;
field.placePlant(this, location); // ensure plant is stored in field
}
public void die()
{
this.alive = false;
field.placePlant(null, location); // remove plant after being eaten
}
public boolean isAlive()
{
return alive;
}
public Color getColor()
{
return PLANT_COLOR;
}
public Location getLocation()
{
return location;
}
}