Mercurial > hg > ristipolku
annotate game/Engine.java @ 75:b586ce4f6d97
Large GUI code cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 03 Mar 2011 04:04:57 +0200 |
parents | 855757ab8580 |
children | 43f68fe605de |
rev | line source |
---|---|
0 | 1 /* |
9 | 2 * Ristipolku Game Engine |
0 | 3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
4 */ | |
9 | 5 package game; |
6 | |
0 | 7 import java.awt.*; |
8 import java.awt.geom.*; | |
1 | 9 import java.awt.event.*; |
7 | 10 import java.awt.image.*; |
11 import java.awt.event.*; | |
25 | 12 import java.awt.font.*; |
9 | 13 import javax.imageio.*; |
7 | 14 import javax.swing.*; |
1 | 15 import java.util.*; |
6 | 16 import java.io.*; |
1 | 17 import game.*; |
37 | 18 import javax.sound.sampled.*; |
21 | 19 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
20 |
75 | 21 class AboutBox extends IDMWidget |
8 | 22 { |
75 | 23 BufferedImage aboutImg; |
24 boolean aboutSecret; | |
25 | |
26 public AboutBox() | |
27 { | |
28 try { | |
29 ResourceLoader res = new ResourceLoader("graphics/girl.jpg"); | |
30 aboutImg = ImageIO.read(res.getStream()); | |
31 } | |
32 catch (IOException e) | |
33 { | |
34 } | |
35 | |
36 aboutSecret = false; | |
37 | |
38 setPos(150f, 150f); | |
39 setSize(600f, 400f); | |
40 } | |
41 | |
42 IDMPoint currPos, currOffs; | |
43 Paint textPaint; | |
44 Font textFont; | |
45 FontMetrics textMetrics; | |
8 | 46 |
75 | 47 public void setTextFont(Font font, FontMetrics metrics) |
48 { | |
49 textFont = font; | |
50 textMetrics = metrics; | |
51 } | |
52 | |
53 public void setTextPaint(Paint paint) | |
8 | 54 { |
75 | 55 textPaint = paint; |
56 } | |
57 | |
58 public void setCurrPos(IDMPoint npos) | |
59 { | |
60 currPos = npos; | |
61 currOffs = new IDMPoint(0, 0); | |
62 } | |
63 | |
64 public void setCurrPos(float x, float y) | |
65 { | |
66 setCurrPos(new IDMPoint(x, y)); | |
8 | 67 } |
68 | |
75 | 69 public void drawString(Graphics2D g, String text) |
8 | 70 { |
75 | 71 Paint savePaint = g.getPaint(); |
72 g.setPaint(textPaint); | |
73 | |
74 int i = 0; | |
75 while (i < text.length()) | |
8 | 76 { |
75 | 77 int p = text.indexOf("\n", i); |
78 boolean linefeed; | |
79 String str; | |
80 if (p > i) | |
81 { | |
82 str = text.substring(i, p); | |
83 i = p + 1; | |
84 linefeed = true; | |
85 } | |
86 else | |
87 { | |
88 str = text.substring(i); | |
89 i += str.length(); | |
90 linefeed = false; | |
91 } | |
92 | |
93 g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y); | |
94 | |
95 if (linefeed) | |
96 { | |
97 currOffs.x = 0; | |
98 currOffs.y += textMetrics.getMaxDescent();; | |
99 } | |
100 else | |
101 { | |
102 currOffs.x += textMetrics.stringWidth(str); | |
103 } | |
8 | 104 } |
75 | 105 |
106 g.setPaint(savePaint); | |
107 } | |
108 | |
109 public void paint(Graphics2D g) | |
110 { | |
111 int x = getScaledX(), y = getScaledY(), | |
112 w = getScaledWidth(), h = getScaledHeight(); | |
113 | |
114 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f)); | |
115 g.fill(new RoundRectangle2D.Float(x, y, w, h, 10, 10)); | |
116 | |
117 setTextFont(G.fonts[1], G.metrics[1]); | |
118 setTextPaint(Color.white); | |
8 | 119 |
75 | 120 setCurrPos(x + 15, y + 15); |
121 drawString(g, "RistiPolku (CrossPaths) v0.5"); | |
122 | |
123 if (aboutSecret) | |
124 { | |
125 g.drawImage(aboutImg, x + 15, y + 35, aboutImg.getWidth(), aboutImg.getHeight(), null); | |
126 | |
127 setCurrPos(x + 225, y + 55); | |
128 drawString(g, | |
129 "Dedicated to my\n" + | |
130 "favorite woman" + | |
131 "in the world."); | |
132 | |
133 setCurrPos(x + 350, y + 155); | |
134 drawString(g, "- Matti"); | |
135 } | |
8 | 136 else |
137 { | |
75 | 138 setTextPaint(Color.yellow); |
139 drawString(g, "(c) Copyright 2011 Matti 'ccr' Hämäläinen\n"); | |
140 | |
141 setTextPaint(Color.white); | |
142 drawString(g, "Programming project for Java-course\n" + | |
143 "T740306 taught by Kari Laitinen."); | |
8 | 144 } |
145 } | |
75 | 146 |
147 public boolean keyPressed(KeyEvent e) | |
148 { | |
149 if (e.getKeyCode() == KeyEvent.VK_L) | |
150 { | |
151 aboutSecret = true; | |
152 } | |
153 else | |
154 { | |
155 clicked(); | |
156 aboutSecret = false; | |
157 } | |
158 return true; | |
159 } | |
8 | 160 |
75 | 161 public void clicked() |
8 | 162 { |
75 | 163 parent.remove(this); |
8 | 164 } |
165 } | |
75 | 166 |
0 | 167 |
48 | 168 class GameBoard extends IDMWidget |
0 | 169 { |
75 | 170 static final int boardSize = 9; |
171 static final int boardMiddle = 4; | |
2 | 172 Piece[][] board; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
173 float pscale; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
174 |
8 | 175 public boolean flagGameOver; |
55 | 176 public int gameScore; |
54 | 177 |
178 public Piece currPiece, nextPiece; | |
41 | 179 int currX, currY, currPoint; |
9 | 180 |
47 | 181 Sound sndPlaced; |
182 | |
75 | 183 public GameBoard(IDMPoint pos, float ps) |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
184 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
185 super(pos); |
75 | 186 pscale = ps; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
187 |
75 | 188 // sndPlaced = smgr.getSound("sounds/placed.wav"); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
189 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
190 startNewGame(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
191 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
192 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
193 public void startNewGame() |
2 | 194 { |
195 board = new Piece[boardSize][boardSize]; | |
196 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | |
197 | |
41 | 198 currX = boardMiddle; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
199 currY = boardMiddle; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
200 currPoint = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
201 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
202 currPiece = null; |
54 | 203 nextPiece = new Piece(PieceType.ACTIVE); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
204 |
65
dc936dba124e
Set game over-flag correctly, so that we reset everything after a game over
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
205 flagGameOver = false; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
206 pieceFinishTurn(); |
55 | 207 gameScore = 0; |
2 | 208 } |
0 | 209 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
210 public void paintBackPlate(Graphics2D g) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
211 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
212 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.2f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
213 g.setStroke(new BasicStroke(5.0f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
214 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(), |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
215 boardSize * pscale, boardSize * pscale, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
216 pscale / 5, pscale / 5)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
217 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
218 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
219 public void paint(Graphics2D g) |
2 | 220 { |
221 for (int y = 0; y < boardSize; y++) | |
222 for (int x = 0; x < boardSize; x++) | |
223 if (board[x][y] != null) | |
224 { | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
225 board[x][y].paint(g, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
226 getScaledX() + (x * pscale), |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
227 getScaledY() + (y * pscale), |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
228 pscale - pscale / 10); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
229 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
230 } |
75 | 231 |
232 public boolean contains(float x, float y) | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
233 { |
75 | 234 boolean foo = (x >= getScaledX() && |
235 y >= getScaledY() && | |
236 x < getScaledX() + boardSize * pscale && | |
237 y < getScaledY() + boardSize * pscale); | |
238 System.out.print("contains "+x+", "+y+" ("+getScaledX()+", "+getScaledY()+", "+(getScaledX() + boardSize * pscale)+"): "+foo+"\n"); | |
239 return foo; | |
2 | 240 } |
9 | 241 |
242 public void animate(float time) | |
243 { | |
244 for (int y = 0; y < boardSize; y++) | |
245 for (int x = 0; x < boardSize; x++) | |
246 if (board[x][y] != null) | |
247 { | |
248 board[x][y].animate(time); | |
249 } | |
250 } | |
1 | 251 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
252 public void pieceRotate(Piece.RotateDir dir) |
2 | 253 { |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
254 if (currPiece != null && !flagGameOver) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
255 { |
41 | 256 currPiece.rotate(dir); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
257 } |
2 | 258 } |
1 | 259 |
75 | 260 // Change coordinates based on the "outgoing" |
261 // piece connection point. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
262 private void pieceMoveTo(int point) |
7 | 263 { |
46 | 264 switch (point) |
265 { | |
266 case 0: currY--; break; | |
267 case 1: currY--; break; | |
268 | |
269 case 2: currX++; break; | |
270 case 3: currX++; break; | |
271 | |
272 case 4: currY++; break; | |
273 case 5: currY++; break; | |
274 | |
275 case 6: currX--; break; | |
276 case 7: currX--; break; | |
277 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
278 } |
9 | 279 |
54 | 280 public void pieceCreateNew() |
281 { | |
282 currPiece = nextPiece; | |
283 nextPiece = new Piece(PieceType.ACTIVE); | |
284 } | |
285 | |
286 public void pieceSwapCurrent() | |
287 { | |
56 | 288 if (!flagGameOver) |
289 { | |
290 Piece tmp = currPiece; | |
291 currPiece = nextPiece; | |
292 nextPiece = tmp; | |
293 board[currX][currY] = currPiece; | |
294 } | |
54 | 295 } |
296 | |
75 | 297 // Check one piece, set connections, find the new placement |
298 // based on piece rotations etc. | |
299 private boolean pieceCheck(Piece piece) | |
48 | 300 { |
53 | 301 if (piece == null) |
48 | 302 { |
303 // Create new piece | |
56 | 304 pieceCreateNew(); |
48 | 305 board[currX][currY] = currPiece; |
306 return true; | |
307 } | |
308 else | |
53 | 309 if (piece.getType() == PieceType.START) |
48 | 310 { |
311 if (currPiece != null) | |
312 { | |
313 // Hit center starting piece, game over | |
314 flagGameOver = true; | |
315 return true; | |
316 } | |
317 else | |
318 { | |
319 // Start piece as first piece means game is starting | |
320 pieceMoveTo(currPoint); | |
54 | 321 pieceCreateNew(); |
48 | 322 board[currX][currY] = currPiece; |
323 return true; | |
324 } | |
325 } | |
326 | |
327 // Mark the current piece as locked | |
53 | 328 piece.setType(PieceType.LOCKED); |
48 | 329 |
330 // Solve connection (with rotations) through the piece | |
53 | 331 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint)); |
48 | 332 |
333 // Mark connection as active | |
53 | 334 piece.setConnectionState(currPoint, true); |
48 | 335 |
336 // Solve exit point (with rotations) | |
53 | 337 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint)); |
48 | 338 |
339 // Move to next position accordingly | |
340 pieceMoveTo(currPoint); | |
341 return false; | |
342 } | |
343 | |
75 | 344 // Finish one move/turn of the game, resolve path and find placement |
345 // of the next piece, or set "game over" state if required. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
346 public void pieceFinishTurn() |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
347 { |
48 | 348 boolean finished = false; |
55 | 349 int connections = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
350 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
351 if (currPiece != null) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
352 { |
75 | 353 G.smgr.play(sndPlaced); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
354 } |
55 | 355 |
48 | 356 while (!finished) |
7 | 357 { |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
358 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) |
27 | 359 { |
55 | 360 connections++; |
48 | 361 finished = pieceCheck(board[currX][currY]); |
27 | 362 } |
363 else | |
364 { | |
46 | 365 // Outside of the board, game over |
48 | 366 finished = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
367 flagGameOver = true; |
7 | 368 } |
369 } | |
53 | 370 |
66 | 371 // Compute and add score |
55 | 372 gameScore += connections * connections; |
373 | |
66 | 374 // If game over, clear the game |
53 | 375 if (flagGameOver) |
376 { | |
377 currPiece = null; | |
378 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
379 } |
66 | 380 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
381 public boolean mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
382 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
383 int notches = e.getWheelRotation(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
384 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
385 if (notches < 0) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
386 pieceRotate(Piece.RotateDir.LEFT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
387 else |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
388 pieceRotate(Piece.RotateDir.RIGHT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
389 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
390 return true; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
391 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
392 |
75 | 393 /* |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
394 public boolean mouseClicked(MouseEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
395 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
396 if (flagGameOver) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
397 return false; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
398 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
399 if (contains(e.getPoint())) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
400 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
401 pieceFinishTurn(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
402 return true; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
403 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
404 else |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
405 return false; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
406 } |
75 | 407 */ |
408 | |
409 public void clicked() | |
410 { | |
411 pieceFinishTurn(); | |
412 } | |
47 | 413 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
414 public boolean keyPressed(KeyEvent e) |
47 | 415 { |
54 | 416 if (flagGameOver) |
417 return false; | |
418 | |
47 | 419 switch (e.getKeyCode()) |
420 { | |
421 case KeyEvent.VK_LEFT: | |
422 case KeyEvent.VK_UP: | |
423 pieceRotate(Piece.RotateDir.LEFT); | |
424 return true; | |
425 | |
426 case KeyEvent.VK_RIGHT: | |
427 case KeyEvent.VK_DOWN: | |
428 pieceRotate(Piece.RotateDir.RIGHT); | |
429 return true; | |
430 | |
431 case KeyEvent.VK_ENTER: | |
432 pieceFinishTurn(); | |
433 return true; | |
434 } | |
435 return false; | |
436 } | |
1 | 437 } |
438 | |
439 | |
9 | 440 public class Engine extends JPanel |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
441 implements Runnable, KeyListener, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
442 MouseListener, MouseWheelListener |
1 | 443 { |
25 | 444 long startTime; |
445 float gameClock, gameFrames; | |
75 | 446 |
8 | 447 Thread animThread; |
448 boolean animEnable = false; | |
25 | 449 |
4 | 450 GameBoard lauta = null; |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
451 InputStream musa; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
452 IDMContainer widgets; |
75 | 453 AboutBox aboutBox; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
454 |
9 | 455 public Engine() |
2 | 456 { |
25 | 457 // Initialize globals |
458 System.out.print("Engine() constructor\n"); | |
459 | |
37 | 460 // Sound system |
75 | 461 G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 4); |
9 | 462 |
25 | 463 // Load resources |
4 | 464 try |
465 { | |
24 | 466 ResourceLoader res = new ResourceLoader("graphics/board.jpg"); |
75 | 467 G.lautaBG = ImageIO.read(res.getStream()); |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
468 |
25 | 469 try { |
470 res = new ResourceLoader("graphics/font.ttf"); | |
75 | 471 |
55 | 472 |
75 | 473 G.fonts = new Font[G.numFonts]; |
474 G.fonts[0] = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); | |
475 G.fonts[1] = G.fonts[0].deriveFont(24f); | |
476 G.fonts[2] = G.fonts[0].deriveFont(64f); | |
477 | |
25 | 478 } |
479 catch (FontFormatException e) | |
480 { | |
481 System.out.print("Could not initialize fonts.\n"); | |
482 } | |
37 | 483 |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
484 res = new ResourceLoader("sounds/gamemusic.wav"); |
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
485 musa = res.getStream(); |
4 | 486 } |
487 catch (IOException e) | |
488 { | |
489 JOptionPane.showMessageDialog(null, | |
21 | 490 e.getMessage(), |
4 | 491 "Initialization error", |
492 JOptionPane.ERROR_MESSAGE); | |
37 | 493 |
21 | 494 System.out.print(e.getMessage()); |
18 | 495 } |
496 | |
52 | 497 // Create IDM GUI widgets |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
498 widgets = new IDMContainer(); |
52 | 499 |
75 | 500 widgets.add(new BtnSwapPiece(767f, 450f)); |
501 widgets.add(new BtnAbout (767f, 570f)); | |
502 widgets.add(new BtnNewGame (767f, 650f)); | |
50 | 503 |
75 | 504 lauta = new GameBoard(new IDMPoint(95, 130), 63); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
505 widgets.add(lauta); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
506 |
75 | 507 aboutBox = new AboutBox(); |
508 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
509 // Game |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
510 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
511 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
512 // Initialize event listeners |
18 | 513 addKeyListener(this); |
514 addMouseListener(this); | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
515 addMouseWheelListener(this); |
18 | 516 |
517 // Get initial focus | |
518 if (!hasFocus()) | |
519 { | |
520 System.out.print("Engine(): requesting focus\n"); | |
521 requestFocus(); | |
4 | 522 } |
37 | 523 |
75 | 524 // G.smgr.play(musa); |
8 | 525 } |
526 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
527 public void startNewGame() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
528 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
529 gameClock = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
530 gameFrames = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
531 startTime = new Date().getTime(); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
532 lauta.startNewGame(); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
533 } |
25 | 534 |
535 public void paintComponent(Graphics g) | |
536 { | |
537 Graphics2D g2 = (Graphics2D) g; | |
538 | |
539 // Use antialiasing when rendering the game elements | |
540 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |
541 RenderingHints.VALUE_ANTIALIAS_ON); | |
542 | |
543 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, | |
544 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |
545 | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
546 |
52 | 547 // Rescale if parent component size has changed |
25 | 548 Dimension dim = getSize(); |
75 | 549 if (G.screenDim == null || !dim.equals(G.screenDim)) |
25 | 550 { |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
551 // Rescale IDM GUI widgets |
75 | 552 widgets.setScale(dim.width / 1024.0f, dim.height / 768.0f); |
553 G.screenDim = dim; | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
554 |
52 | 555 // Rescale background image |
75 | 556 G.lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); |
557 Graphics2D gimg = G.lautaBGScaled.createGraphics(); | |
25 | 558 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
559 RenderingHints.VALUE_INTERPOLATION_BICUBIC); | |
560 | |
75 | 561 gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
562 lauta.paintBackPlate(gimg); |
25 | 563 |
564 System.out.print("scale changed\n"); | |
565 } | |
566 | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
567 // Get font metrics against current Graphics2D context |
75 | 568 if (G.metrics == null) |
569 { | |
570 G.metrics = new FontMetrics[G.numFonts]; | |
571 for (int i = 0; i < G.numFonts; i++) | |
572 G.metrics[i] = g2.getFontMetrics(G.fonts[i]); | |
573 } | |
55 | 574 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
575 // Draw background image, pieces, widgets |
75 | 576 g2.drawImage(G.lautaBGScaled, 0, 0, null); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
577 widgets.paint(g2); |
55 | 578 |
579 if (!lauta.flagGameOver) | |
580 { | |
62
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
581 if (lauta.nextPiece != null) |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
582 { |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
583 // Draw next piece |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
584 AffineTransform save = g2.getTransform(); |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
585 lauta.nextPiece.paint(g2, 830, 325, 90); |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
586 g2.setTransform(save); |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
587 } |
55 | 588 } |
589 else | |
590 { | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
591 // Game over text |
55 | 592 String text = "Game Over!"; |
75 | 593 int textWidth = G.metrics[2].stringWidth(text); |
594 g2.setFont(G.fonts[2]); | |
55 | 595 |
596 g2.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f)); | |
597 g2.drawString(text, (dim.width - textWidth) / 2 + 5, dim.height / 2 + 5); | |
598 | |
599 double f = Math.sin(gameClock * 0.1) * 4.0; | |
600 g2.setPaint(Color.white); | |
601 g2.drawString(text, (dim.width - textWidth) / 2 + (float) f, dim.height / 2 + (float) f); | |
602 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
603 |
75 | 604 // Score |
605 g2.setFont(G.fonts[2]); | |
25 | 606 g2.setPaint(Color.white); |
55 | 607 g2.drawString(""+ String.format("%05d", lauta.gameScore), dim.width - 230, 220); |
608 | |
75 | 609 |
610 // Frames per second counter | |
611 g2.setFont(G.fonts[1]); | |
25 | 612 long currTime = new Date().getTime(); |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
613 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
614 |
75 | 615 gameFrames++; |
25 | 616 } |
617 | |
8 | 618 public void startThreads() |
619 { | |
9 | 620 System.out.print("startThreads()\n"); |
8 | 621 if (animThread == null) |
622 { | |
623 animThread = new Thread(this); | |
624 animEnable = true; | |
625 animThread.start(); | |
626 } | |
627 } | |
628 | |
629 public void stopThreads() | |
630 { | |
9 | 631 System.out.print("stopThreads()\n"); |
37 | 632 |
633 // Stop animations | |
8 | 634 if (animThread != null) |
635 { | |
636 animThread.interrupt(); | |
637 animEnable = false; | |
638 animThread = null; | |
639 } | |
22 | 640 |
37 | 641 // Shut down sound manager |
75 | 642 G.smgr.close(); |
2 | 643 } |
0 | 644 |
75 | 645 public void mouseEntered(MouseEvent e) |
646 { | |
647 widgets.mouseEntered(e); | |
648 } | |
649 public void mouseExited(MouseEvent e) | |
650 { | |
651 widgets.mouseExited(e); | |
652 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
653 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
654 public void mousePressed(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
655 { |
75 | 656 if (widgets.containsObject(aboutBox)) |
657 aboutBox.mousePressed(e); | |
658 else | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
659 widgets.mousePressed(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
660 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
661 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
662 public void mouseReleased(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
663 { |
75 | 664 if (widgets.containsObject(aboutBox)) |
665 aboutBox.mouseReleased(e); | |
666 else | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
667 widgets.mouseReleased(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
668 } |
18 | 669 |
670 public void mouseClicked(MouseEvent e) | |
671 { | |
672 if (!hasFocus()) | |
673 { | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
674 System.out.print("Requesting focus\n"); |
18 | 675 requestFocus(); |
676 } | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
677 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
678 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
679 public void mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
680 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
681 lauta.mouseWheelMoved(e); |
18 | 682 } |
683 | |
75 | 684 public void keyTyped(KeyEvent e) { } |
685 public void keyReleased(KeyEvent e) { } | |
1 | 686 |
9 | 687 public void keyPressed(KeyEvent e) |
2 | 688 { |
75 | 689 // Handle keyboard input |
690 if (widgets.containsObject(aboutBox)) | |
691 aboutBox.keyPressed(e); | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
692 else |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
693 widgets.keyPressed(e); |
2 | 694 } |
8 | 695 |
696 public void run() | |
697 { | |
698 while (animEnable) | |
699 { | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
700 // Progress game animation clock |
25 | 701 gameClock++; |
9 | 702 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
703 // Animate components |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
704 lauta.animate(gameClock); |
62
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
705 if (lauta.nextPiece != null) |
caf67c7e0814
Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
706 lauta.nextPiece.animate(gameClock); |
9 | 707 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
708 // Repaint with a frame limiter |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
709 if (gameClock % 4 == 1) |
10 | 710 repaint(); |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
711 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
712 // Sleep for a moment |
9 | 713 try { |
714 Thread.sleep(10); | |
715 } | |
716 catch (InterruptedException x) { | |
717 } | |
8 | 718 } |
719 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
720 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
721 class BtnNewGame extends IDMButton |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
722 { |
51 | 723 public BtnNewGame(float x, float y) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
724 { |
75 | 725 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "New Game"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
726 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
727 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
728 public void clicked() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
729 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
730 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
731 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
732 } |
50 | 733 |
734 class BtnSwapPiece extends IDMButton | |
735 { | |
51 | 736 public BtnSwapPiece(float x, float y) |
50 | 737 { |
75 | 738 super(x, y, KeyEvent.VK_SPACE, G.fonts[1], "Swap"); |
50 | 739 } |
740 | |
741 public void clicked() | |
742 { | |
54 | 743 lauta.pieceSwapCurrent(); |
50 | 744 } |
745 } | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
746 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
747 class BtnAbout extends IDMButton |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
748 { |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
749 public BtnAbout(float x, float y) |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
750 { |
75 | 751 super(x, y, KeyEvent.VK_A, G.fonts[1], "About"); |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
752 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
753 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
754 public void clicked() |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
755 { |
75 | 756 if (!widgets.containsObject(aboutBox)) |
757 widgets.add(aboutBox); | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
758 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
759 } |
0 | 760 } |