forked from finneyj/GameArena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObject.java
49 lines (39 loc) · 1.45 KB
/
GameObject.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
package game_arena;
import java.awt.*;
import java.util.HashMap;
public abstract class GameObject {
private static final HashMap<String, Color> colours = new HashMap<>();
static {
colours.put("BLACK", Color.BLACK);
colours.put("BLUE", Color.BLUE);
colours.put("CYAN", Color.CYAN);
colours.put("DARKGREY", Color.DARK_GRAY);
colours.put("GREY", Color.GRAY);
colours.put("GREEN", Color.GREEN);
colours.put("LIGHTGREY", Color.LIGHT_GRAY);
colours.put("MAGENTA", Color.MAGENTA);
colours.put("ORANGE", Color.ORANGE);
colours.put("PINK", Color.PINK);
colours.put("RED", Color.RED);
colours.put("WHITE", Color.WHITE);
colours.put("YELLOW", Color.YELLOW);
}
abstract void paint(Graphics2D graphics);
//
// Shouldn't really handle colour this way, but the student's haven't been introduced
// to constants properly yet
//
protected Color getColourFromString(String colour) {
Color c = colours.get(colour.toUpperCase());
if (c == null && colour.startsWith("#")) {
int r = Integer.valueOf(colour.substring(1, 3), 16);
int g = Integer.valueOf(colour.substring(3, 5), 16);
int b = Integer.valueOf(colour.substring(5, 7), 16);
c = new Color(r, g, b);
colours.put(colour.toUpperCase(), c);
}
if (c == null)
c = Color.WHITE;
return c;
}
}