-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOceanHex.java
103 lines (95 loc) · 3.96 KB
/
OceanHex.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class OceanHex extends Hex {
public enum Port{Wood, Brick, Sheep, Wheat, Rock, ThreeOne, Ocean}
private Port type;
public OceanHex(Port p, int x, int y, int w) {
super(x,y,w);
type = p;
}
public void draw(Graphics g) {
g.setColor(Color.BLACK);
g.drawPolygon(getXPoints(), getYPoints(), 6);
g.setColor(new Color(113,203,237));
g.fillPolygon(getXPoints(), getYPoints(), 6);
if(type == Port.Wood) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(new Color(0,100,0));
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.WHITE);
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
String str = "2:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
else if(type == Port.Brick) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(new Color(204,0,0));
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.WHITE);
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
String str = "2:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
else if(type == Port.Sheep) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(new Color(0,255,0));
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.BLACK);
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
String str = "2:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
else if(type == Port.Wheat) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(new Color(204,204,0));
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.BLACK);
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
String str = "2:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
else if(type == Port.Rock) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(new Color(96,96,96));
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.WHITE);
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
String str = "2:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
else if(type == Port.ThreeOne) {
g.setColor(Color.WHITE);
g.drawOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.fillOval(getXLoc() - getWidth()/4, getYLoc() - getHeight()/4, getWidth()/2, getHeight()/2);
g.setColor(Color.BLACK);
g.setColor(Color.BLACK);
g.setFont(new Font("TimesRoman", Font.PLAIN, 14));
String str = "3:1";
int textWidth = g.getFontMetrics().stringWidth(str);
int textAscent = g.getFontMetrics().getAscent();
g.drawString(str, getXLoc() - textWidth/2, getYLoc() + textAscent/2);
}
}
public TerrainHex.Resource getResource() {
return null;
}
public Type getType() {
return null;
}
}