1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.curre.prefcount.gui;
16
17 import java.awt.geom.Point2D;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23
24
25
26
27
28
29
30
31
32 public class ScoreBoardLocationsMap {
33
34
35 public static final String PLAYER_NAME = "NAME";
36
37
38 public static final String PLAYER_MOUNT = "MOUNT";
39
40
41 public static final String PLAYER_BULLET = "BULLET";
42
43
44
45
46
47
48 public static final String VISTS_FOR = "VISTS_FOR_";
49
50
51
52
53
54
55 public static final String VIST_SALDO_FOR = "VIST_SALDO_FOR_";
56
57
58 public static final String VIST_SALDO = "VIST_SALDO";
59
60
61 public static final String FINAL_MOUNT = "FINAL_MOUNT";
62
63
64 public static final String FINAL_SCORE = "FINAL_SCORE";
65
66
67 private ScoreBoardPanel scoreBoard;
68
69
70 private float width;
71
72
73 private float height;
74
75
76
77
78
79 private int numberOfPlayers;
80
81
82
83
84
85 private List<Map<String, Point2D.Float>> locationMapsList;
86
87
88
89
90
91
92
93
94 public ScoreBoardLocationsMap(ScoreBoardPanel scoreBoard) {
95 this.scoreBoard = scoreBoard;
96 this.width = 0;
97 this.height = 0;
98 }
99
100
101
102
103
104
105
106
107
108
109 public void initialize(int numberOfPlayers) {
110 if (numberOfPlayers != 3 && numberOfPlayers != 4) {
111 throw new IllegalArgumentException(numberOfPlayers + " number of players is NOT supported!");
112 }
113 this.numberOfPlayers = numberOfPlayers;
114 locationMapsList = new ArrayList<Map<String, Point2D.Float>>(numberOfPlayers);
115 for (int ind = 0; ind < numberOfPlayers; ++ind) {
116 locationMapsList.add(ind, new HashMap<String, Point2D.Float>());
117 }
118 computeLocations();
119 }
120
121
122
123
124
125
126
127 public Map<String, Point2D.Float> getLocationsMap(int playerIndex) {
128 if (playerIndex >= locationMapsList.size() || locationMapsList.size() < 0) {
129 throw new IllegalArgumentException("Wrong index " + playerIndex +
130 " for map of size " + locationMapsList.size());
131 }
132 return locationMapsList.get(playerIndex);
133 }
134
135
136
137
138
139
140
141
142 public void computeLocations() {
143
144
145
146 final float newWidth = scoreBoard.getWidth();
147 final float newHeight = scoreBoard.getHeight();
148 if (width == newWidth && height == newHeight) {
149 return;
150 }
151 width = newWidth;
152 height = newHeight;
153
154 final float centerX = newWidth / 2f;
155 final float centerY = newHeight / 2f;
156 final float incrX = centerX / 3f;
157 final float incrY = centerY / 3f - 7f;
158
159 final float oneFourthX = newWidth / 4f;
160 final float threeFourthX = oneFourthX * 3f;
161
162 final float oneThirdX = newWidth / 3f;
163 final float twoThirdX = oneThirdX * 2f;
164 final float oneThirdY = newHeight / 3f;
165 final float twoThirdY = oneThirdY * 2f;
166
167 final float centX = centerX - 5f;
168 final float centY = centerY + 5f;
169 final float tempX = newWidth - incrX;
170 final int moreX = ((int) incrX) >> 1;
171 final float tempY = newHeight - 12f;
172
173
174 switch (numberOfPlayers) {
175 case(3):
176
177
178 Map<String, Point2D.Float> locationsMap = locationMapsList.get(0);
179 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX + 12f, centY - 7f));
180 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(centerX + 14f, oneThirdY + 12f));
181 locationsMap.put(PLAYER_BULLET, new Point2D.Float(centerX + 14f, incrY + 26f));
182 locationsMap.put(VISTS_FOR + "1", new Point2D.Float(tempX + 10f, incrY + 34f));
183 locationsMap.put(VISTS_FOR + "2", new Point2D.Float(centerX + 20f, 24f));
184 locationsMap.put(VIST_SALDO_FOR + "1", new Point2D.Float(tempX + 25f, newHeight - incrY - 30f));
185 locationsMap.put(VIST_SALDO_FOR + "2", new Point2D.Float(centerX + moreX + 20f, 34f));
186 locationsMap.put(VIST_SALDO, new Point2D.Float(tempX + 25f, centerY));
187 locationsMap.put(FINAL_MOUNT, new Point2D.Float(centerX + 40f, centerY - 20f));
188 locationsMap.put(FINAL_SCORE, new Point2D.Float(centerX + 100f, incrY + 70f));
189
190
191 locationsMap = locationMapsList.get(1);
192 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX - 2f, centY + 17f));
193 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(oneThirdX + 28f, twoThirdY - 2f));
194 locationsMap.put(PLAYER_BULLET, new Point2D.Float(incrX + 32f, (newHeight - incrY) - 14f));
195 locationsMap.put(VISTS_FOR + "0", new Point2D.Float(centerX + 20f, tempY));
196 locationsMap.put(VISTS_FOR + "2", new Point2D.Float(40f, tempY));
197 locationsMap.put(VIST_SALDO_FOR + "0", new Point2D.Float(twoThirdX + 12f + moreX, tempY - 10f));
198 locationsMap.put(VIST_SALDO_FOR + "2", new Point2D.Float(38f + moreX, tempY - 10f));
199 locationsMap.put(VIST_SALDO, new Point2D.Float(centerX + 20f, tempY - 30f));
200 locationsMap.put(FINAL_MOUNT, new Point2D.Float(centerX, twoThirdY - 22f));
201 locationsMap.put(FINAL_SCORE, new Point2D.Float(centerX, newHeight - incrY - 34f));
202
203
204 locationsMap = locationMapsList.get(2);
205 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX - 17f, centY - 7f));
206 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(oneThirdX + 4f, oneThirdY + 12f));
207 locationsMap.put(PLAYER_BULLET, new Point2D.Float(incrX + 10f, incrY + 26f));
208 locationsMap.put(VISTS_FOR + "0", new Point2D.Float(40f, 24f));
209 locationsMap.put(VISTS_FOR + "1", new Point2D.Float(16f, incrY + 34f));
210 locationsMap.put(VIST_SALDO_FOR + "0", new Point2D.Float(centerX - 60f, 34f));
211 locationsMap.put(VIST_SALDO_FOR + "1", new Point2D.Float(31f, newHeight - incrY - 30f));
212 locationsMap.put(VIST_SALDO, new Point2D.Float(41f, centerY));
213 locationsMap.put(FINAL_MOUNT, new Point2D.Float(oneThirdX + 10f, centerY + 20f));
214 locationsMap.put(FINAL_SCORE, new Point2D.Float(oneFourthX - 20f, centerY + 40f));
215 break;
216
217 case(4):
218
219 locationsMap = locationMapsList.get(0);
220 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX, centY - 17f));
221 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(oneThirdX + 24f, oneThirdY + 12f));
222 locationsMap.put(PLAYER_BULLET, new Point2D.Float(incrX + 32f, incrY + 26f));
223 locationsMap.put(VISTS_FOR + "1", new Point2D.Float(twoThirdX + 14f, 24f));
224 locationsMap.put(VISTS_FOR + "2", new Point2D.Float(oneThirdX + 14f, 24f));
225 locationsMap.put(VISTS_FOR + "3", new Point2D.Float(40f, 24f));
226 locationsMap.put(VIST_SALDO_FOR + "1", new Point2D.Float(twoThirdX + moreX, 34f));
227 locationsMap.put(VIST_SALDO_FOR + "2", new Point2D.Float(oneThirdX + moreX, 34f));
228 locationsMap.put(VIST_SALDO_FOR + "3", new Point2D.Float(40f + moreX, 34f));
229 locationsMap.put(VIST_SALDO, new Point2D.Float(centerX, 54));
230 locationsMap.put(FINAL_MOUNT, new Point2D.Float(centerX, oneThirdY + 22f));
231 locationsMap.put(FINAL_SCORE, new Point2D.Float(centerX, incrY + 50f));
232
233
234 locationsMap = locationMapsList.get(1);
235 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX + 17f, centY));
236 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(twoThirdX - 44f, oneThirdY + 60f));
237 locationsMap.put(PLAYER_BULLET, new Point2D.Float(twoThirdX + 16f, oneThirdY + 12f));
238 locationsMap.put(VISTS_FOR + "0", new Point2D.Float(tempX + 10f, incrY + 22f));
239 locationsMap.put(VISTS_FOR + "2", new Point2D.Float(tempX + 10f, twoThirdY + 22f));
240 locationsMap.put(VISTS_FOR + "3", new Point2D.Float(tempX + 10f, oneThirdY + 22f));
241 locationsMap.put(VIST_SALDO_FOR + "0", new Point2D.Float(tempX + 25f, incrY + 47f));
242 locationsMap.put(VIST_SALDO_FOR + "2", new Point2D.Float(tempX + 25f, twoThirdY + 47f));
243 locationsMap.put(VIST_SALDO_FOR + "3", new Point2D.Float(tempX + 25f, oneThirdY + 47f));
244 locationsMap.put(VIST_SALDO, new Point2D.Float(tempX + 35f, centerY));
245 locationsMap.put(FINAL_MOUNT, new Point2D.Float(twoThirdX - 29f, centerY + 20f));
246 locationsMap.put(FINAL_SCORE, new Point2D.Float(threeFourthX, centerY - 20f));
247
248
249 locationsMap = locationMapsList.get(2);
250 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX, centY + 17f));
251 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(oneThirdX + 28f, twoThirdY - 2f));
252 locationsMap.put(PLAYER_BULLET, new Point2D.Float(incrX + 32f, newHeight - incrY - 14f));
253 locationsMap.put(VISTS_FOR + "0", new Point2D.Float(oneThirdX + 12f, tempY));
254 locationsMap.put(VISTS_FOR + "1", new Point2D.Float(twoThirdX + 12f, tempY));
255 locationsMap.put(VISTS_FOR + "3", new Point2D.Float(38f, tempY));
256 locationsMap.put(VIST_SALDO_FOR + "0", new Point2D.Float(oneThirdX + 12f + moreX, tempY - 10f));
257 locationsMap.put(VIST_SALDO_FOR + "1", new Point2D.Float(twoThirdX + 12f + moreX, tempY - 10f));
258 locationsMap.put(VIST_SALDO_FOR + "3", new Point2D.Float(38f + moreX, tempY - 10f));
259 locationsMap.put(VIST_SALDO, new Point2D.Float(centerX, tempY - 30f));
260 locationsMap.put(FINAL_MOUNT, new Point2D.Float(centerX, twoThirdY - 22f));
261 locationsMap.put(FINAL_SCORE, new Point2D.Float(centerX, newHeight - incrY - 34f));
262
263
264 locationsMap = locationMapsList.get(3);
265 locationsMap.put(PLAYER_NAME, new Point2D.Float(centX - 17f, centY));
266 locationsMap.put(PLAYER_MOUNT, new Point2D.Float(oneThirdX + 4f, oneThirdY + 60f));
267 locationsMap.put(PLAYER_BULLET, new Point2D.Float(incrX + 10f, oneThirdY - 8f));
268 locationsMap.put(VISTS_FOR + "0", new Point2D.Float(16f, oneThirdY - 8f));
269 locationsMap.put(VISTS_FOR + "1", new Point2D.Float(16f, twoThirdY - 8f));
270 locationsMap.put(VISTS_FOR + "2", new Point2D.Float(16f, newHeight - 66f));
271 locationsMap.put(VIST_SALDO_FOR + "0", new Point2D.Float(31f, oneThirdY - 33f));
272 locationsMap.put(VIST_SALDO_FOR + "1", new Point2D.Float(31f, twoThirdY - 33f));
273 locationsMap.put(VIST_SALDO_FOR + "2", new Point2D.Float(31f, newHeight - 91f));
274 locationsMap.put(VIST_SALDO, new Point2D.Float(41f, centerY));
275 locationsMap.put(FINAL_MOUNT, new Point2D.Float(oneThirdX + 10f, centerY + 20f));
276 locationsMap.put(FINAL_SCORE, new Point2D.Float(oneFourthX - 10f, centerY + 40f));
277 break;
278
279 default:
280 throw new UnsupportedOperationException(numberOfPlayers + " number of players is NOT supported!");
281 }
282 }
283
284
285
286 }