-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreature.java
58 lines (44 loc) · 1.04 KB
/
Creature.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
// Creature.java
package com.maxim;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
// initialize the abstract class
public abstract class Creature
{
private static String imgFile;
protected GridLocation location; // all variables shared by all creatures
protected FlyWorld world;
protected BufferedImage image;
// constructor takes location, flyWorld and name of file
public Creature(GridLocation loc, FlyWorld fw, String imgF)
{
location = loc;
world = fw;
imgFile = imgF;
try
{
image = ImageIO.read(new File(imgFile));
}
catch (IOException ioe)
{
System.out.println("Unable to read image file: " + imgFile);
System.exit(0);
}
// Puts the fly on the GridLocation so image displays
location.setCreature(this);
}
public BufferedImage getImage()
{
return image;
}
public GridLocation getLocation()
{
return location;
}
public boolean isPredator()
{
return false;
}
}