Mercurial > hg > ristipolku
annotate game/Engine.java @ 54:cc7943cd7f2d
Moar work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 23 Feb 2011 19:54:48 +0200 |
parents | 6bf4675e2d96 |
children | 974ec36c562e |
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 |
8 | 21 /* |
22 class AnimatedElement | |
23 { | |
24 float x, y, stime, value; | |
25 Interpolate lerp; | |
26 boolean active; | |
27 | |
28 public AnimatedElement(float x, float y, ) | |
29 { | |
30 stime = 0; | |
31 this.x = x; | |
32 this.y = y; | |
33 | |
34 } | |
35 | |
36 public animate(float time) | |
37 { | |
38 if (!active) | |
39 { | |
40 active = true; | |
41 stime = time; | |
42 } | |
43 | |
44 float t = (time - stime) / 10.0f; | |
45 if (t < 100) | |
46 value = lerp.getValue(t); | |
47 else | |
48 { | |
49 | |
50 } | |
51 } | |
52 | |
53 public paint(Graphics2D g, ); | |
54 { | |
55 } | |
56 } | |
57 */ | |
0 | 58 |
48 | 59 class GameBoard extends IDMWidget |
0 | 60 { |
2 | 61 public static final int boardSize = 9; |
62 public static final int boardMiddle = 4; | |
63 Piece[][] board; | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
64 |
8 | 65 public boolean flagGameOver; |
54 | 66 |
67 public Piece currPiece, nextPiece; | |
41 | 68 int currX, currY, currPoint; |
9 | 69 |
48 | 70 int score; |
71 | |
47 | 72 SoundManager soundManager; |
73 Sound sndPlaced; | |
74 | |
75 public GameBoard(SoundManager smgr) | |
2 | 76 { |
77 board = new Piece[boardSize][boardSize]; | |
78 | |
79 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | |
80 | |
41 | 81 currX = boardMiddle; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
82 currY = boardMiddle; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
83 currPoint = 0; |
8 | 84 |
54 | 85 nextPiece = new Piece(PieceType.ACTIVE); |
9 | 86 pieceFinishTurn(); |
8 | 87 |
88 flagGameOver = false; | |
48 | 89 score = 0; |
47 | 90 |
91 soundManager = smgr; | |
50 | 92 // sndPlaced = soundManager.getSound("sounds/placed.wav"); |
2 | 93 } |
0 | 94 |
51 | 95 public void paint(Graphics2D g, float sx, float sy, float scale) |
2 | 96 { |
97 for (int y = 0; y < boardSize; y++) | |
98 for (int x = 0; x < boardSize; x++) | |
99 if (board[x][y] != null) | |
100 { | |
6 | 101 AffineTransform save = g.getTransform(); |
102 | |
4 | 103 board[x][y].paint(g, |
104 sx + (x * scale), | |
105 sy + (y * scale), | |
106 scale - scale / 10); | |
6 | 107 |
108 g.setTransform(save); | |
2 | 109 } |
110 } | |
9 | 111 |
112 public void animate(float time) | |
113 { | |
114 for (int y = 0; y < boardSize; y++) | |
115 for (int x = 0; x < boardSize; x++) | |
116 if (board[x][y] != null) | |
117 { | |
118 board[x][y].animate(time); | |
119 } | |
120 } | |
1 | 121 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
122 public void pieceRotate(Piece.RotateDir dir) |
2 | 123 { |
41 | 124 if (currPiece != null) |
125 currPiece.rotate(dir); | |
2 | 126 } |
1 | 127 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
128 private void pieceMoveTo(int point) |
7 | 129 { |
46 | 130 switch (point) |
131 { | |
132 case 0: currY--; break; | |
133 case 1: currY--; break; | |
134 | |
135 case 2: currX++; break; | |
136 case 3: currX++; break; | |
137 | |
138 case 4: currY++; break; | |
139 case 5: currY++; break; | |
140 | |
141 case 6: currX--; break; | |
142 case 7: currX--; break; | |
143 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
144 } |
9 | 145 |
54 | 146 public void pieceCreateNew() |
147 { | |
148 currPiece = nextPiece; | |
149 nextPiece = new Piece(PieceType.ACTIVE); | |
150 } | |
151 | |
152 public void pieceSwapCurrent() | |
153 { | |
154 Piece tmp = currPiece; | |
155 currPiece = nextPiece; | |
156 nextPiece = tmp; | |
157 board[currX][currY] = currPiece; | |
158 } | |
159 | |
53 | 160 public boolean pieceCheck(Piece piece) |
48 | 161 { |
53 | 162 if (piece == null) |
48 | 163 { |
164 // Create new piece | |
165 currPiece = new Piece(PieceType.ACTIVE); | |
166 board[currX][currY] = currPiece; | |
167 return true; | |
168 } | |
169 else | |
53 | 170 if (piece.getType() == PieceType.START) |
48 | 171 { |
172 if (currPiece != null) | |
173 { | |
174 // Hit center starting piece, game over | |
175 flagGameOver = true; | |
176 return true; | |
177 } | |
178 else | |
179 { | |
180 // Start piece as first piece means game is starting | |
181 pieceMoveTo(currPoint); | |
54 | 182 pieceCreateNew(); |
48 | 183 board[currX][currY] = currPiece; |
184 return true; | |
185 } | |
186 } | |
187 | |
188 // Mark the current piece as locked | |
53 | 189 piece.setType(PieceType.LOCKED); |
48 | 190 |
191 // Solve connection (with rotations) through the piece | |
53 | 192 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint)); |
48 | 193 |
194 // Mark connection as active | |
53 | 195 piece.setConnectionState(currPoint, true); |
48 | 196 |
197 // Solve exit point (with rotations) | |
53 | 198 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint)); |
48 | 199 |
200 // Move to next position accordingly | |
201 pieceMoveTo(currPoint); | |
202 return false; | |
203 } | |
204 | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
205 public void pieceFinishTurn() |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
206 { |
48 | 207 boolean finished = false; |
208 while (!finished) | |
7 | 209 { |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
210 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) |
27 | 211 { |
48 | 212 finished = pieceCheck(board[currX][currY]); |
27 | 213 } |
214 else | |
215 { | |
46 | 216 // Outside of the board, game over |
48 | 217 finished = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
218 flagGameOver = true; |
7 | 219 } |
220 } | |
53 | 221 |
222 if (flagGameOver) | |
223 { | |
224 currPiece = null; | |
225 System.out.print("GameOver!\n"); | |
226 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
227 } |
47 | 228 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
229 public boolean keyPressed(KeyEvent e) |
47 | 230 { |
54 | 231 if (flagGameOver) |
232 return false; | |
233 | |
47 | 234 switch (e.getKeyCode()) |
235 { | |
236 case KeyEvent.VK_LEFT: | |
237 case KeyEvent.VK_UP: | |
238 pieceRotate(Piece.RotateDir.LEFT); | |
239 return true; | |
240 | |
241 case KeyEvent.VK_RIGHT: | |
242 case KeyEvent.VK_DOWN: | |
243 pieceRotate(Piece.RotateDir.RIGHT); | |
244 return true; | |
245 | |
246 case KeyEvent.VK_ENTER: | |
247 soundManager.play(sndPlaced); | |
248 pieceFinishTurn(); | |
249 return true; | |
250 } | |
251 return false; | |
252 } | |
1 | 253 } |
254 | |
255 | |
9 | 256 public class Engine extends JPanel |
18 | 257 implements Runnable, KeyListener, MouseListener |
1 | 258 { |
25 | 259 long startTime; |
260 float gameClock, gameFrames; | |
8 | 261 Thread animThread; |
262 boolean animEnable = false; | |
25 | 263 |
264 Font fontMain, font1, font2; | |
4 | 265 GameBoard lauta = null; |
9 | 266 BufferedImage lautaBG = null, lautaBGScaled = null; |
25 | 267 Dimension lautaDim; |
22 | 268 |
37 | 269 static final AudioFormat sfmt = new AudioFormat(22050, 16, 1, true, false); |
47 | 270 SoundManager soundManager; |
271 Sound musa; | |
1 | 272 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
273 IDMContainer widgets; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
274 |
9 | 275 public Engine() |
2 | 276 { |
25 | 277 // Initialize globals |
278 System.out.print("Engine() constructor\n"); | |
279 | |
37 | 280 // Sound system |
47 | 281 soundManager = new SoundManager(sfmt, 16); |
9 | 282 |
25 | 283 // Load resources |
4 | 284 try |
285 { | |
24 | 286 ResourceLoader res = new ResourceLoader("graphics/board.jpg"); |
18 | 287 lautaBG = ImageIO.read(res.getStream()); |
21 | 288 |
25 | 289 try { |
290 res = new ResourceLoader("graphics/font.ttf"); | |
291 fontMain = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); | |
292 font1 = fontMain.deriveFont(24f); | |
293 font2 = fontMain.deriveFont(32f); | |
294 } | |
295 catch (FontFormatException e) | |
296 { | |
297 System.out.print("Could not initialize fonts.\n"); | |
298 } | |
37 | 299 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
300 // musa = smgr.getSound("sounds/gamemusic.wav"); |
4 | 301 } |
302 catch (IOException e) | |
303 { | |
304 JOptionPane.showMessageDialog(null, | |
21 | 305 e.getMessage(), |
4 | 306 "Initialization error", |
307 JOptionPane.ERROR_MESSAGE); | |
37 | 308 |
21 | 309 System.out.print(e.getMessage()); |
18 | 310 } |
311 | |
52 | 312 // 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
|
313 widgets = new IDMContainer(); |
52 | 314 |
315 widgets.add(new BtnSwapPiece(0.75f, 0.60f)); | |
316 widgets.add(new BtnNewGame(0.75f, 0.85f)); | |
50 | 317 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
318 // Game |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
319 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
320 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
321 // Initialize event listeners |
18 | 322 addKeyListener(this); |
323 addMouseListener(this); | |
324 | |
325 // Get initial focus | |
326 if (!hasFocus()) | |
327 { | |
328 System.out.print("Engine(): requesting focus\n"); | |
329 requestFocus(); | |
4 | 330 } |
37 | 331 |
47 | 332 soundManager.play(musa); |
8 | 333 } |
334 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
335 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
|
336 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
337 gameClock = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
338 gameFrames = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
339 startTime = new Date().getTime(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
340 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
341 lauta = new GameBoard(soundManager); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
342 } |
25 | 343 |
344 public void paintComponent(Graphics g) | |
345 { | |
346 Graphics2D g2 = (Graphics2D) g; | |
347 | |
348 // Use antialiasing when rendering the game elements | |
349 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |
350 RenderingHints.VALUE_ANTIALIAS_ON); | |
351 | |
352 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, | |
353 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |
354 | |
52 | 355 // Rescale if parent component size has changed |
25 | 356 Dimension dim = getSize(); |
357 if (lautaDim == null || !dim.equals(lautaDim)) | |
358 { | |
52 | 359 // Rescale background image |
25 | 360 lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); |
361 Graphics2D gimg = lautaBGScaled.createGraphics(); | |
362 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, | |
363 RenderingHints.VALUE_INTERPOLATION_BICUBIC); | |
364 | |
365 gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); | |
366 lautaDim = dim; | |
367 | |
52 | 368 // Rescale IDM GUI widgets |
51 | 369 widgets.setScale(dim.width, dim.height); |
52 | 370 |
25 | 371 System.out.print("scale changed\n"); |
372 } | |
373 | |
52 | 374 // Background image, pieces |
25 | 375 g2.drawImage(lautaBGScaled, 0, 0, null); |
52 | 376 lauta.paint(g2, 90, 140, 65); |
54 | 377 lauta.nextPiece.paint(g2, 830, 325, 90); |
50 | 378 widgets.paint(g2); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
379 |
52 | 380 // Scores, etc |
25 | 381 g2.setFont(font1); |
382 g2.setPaint(Color.white); | |
50 | 383 |
25 | 384 long currTime = new Date().getTime(); |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
385 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); |
25 | 386 } |
387 | |
8 | 388 public void startThreads() |
389 { | |
9 | 390 System.out.print("startThreads()\n"); |
8 | 391 if (animThread == null) |
392 { | |
393 animThread = new Thread(this); | |
394 animEnable = true; | |
395 animThread.start(); | |
396 } | |
397 } | |
398 | |
399 public void stopThreads() | |
400 { | |
9 | 401 System.out.print("stopThreads()\n"); |
37 | 402 |
403 // Stop animations | |
8 | 404 if (animThread != null) |
405 { | |
406 animThread.interrupt(); | |
407 animEnable = false; | |
408 animThread = null; | |
409 } | |
22 | 410 |
37 | 411 // Shut down sound manager |
47 | 412 soundManager.close(); |
2 | 413 } |
0 | 414 |
18 | 415 public void mouseEntered(MouseEvent e) { } |
416 public void mouseExited(MouseEvent e) { } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
417 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
418 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
|
419 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
420 widgets.mousePressed(e); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
421 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
422 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
423 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
|
424 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
425 widgets.mouseReleased(e); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
426 } |
18 | 427 |
428 public void mouseClicked(MouseEvent e) | |
429 { | |
430 System.out.print("mouseClicked()\n"); | |
431 if (!hasFocus()) | |
432 { | |
433 System.out.print("requesting focus\n"); | |
434 requestFocus(); | |
435 } | |
436 } | |
437 | |
9 | 438 public void keyTyped(KeyEvent e) |
2 | 439 { |
440 } | |
1 | 441 |
2 | 442 public void keyReleased(KeyEvent e) |
443 { | |
444 } | |
1 | 445 |
9 | 446 public void keyPressed(KeyEvent e) |
2 | 447 { |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
448 // Handle keyboard input |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
449 if (lauta.keyPressed(e)) |
47 | 450 return; |
451 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
452 widgets.keyPressed(e); |
2 | 453 } |
8 | 454 |
455 public void run() | |
456 { | |
457 while (animEnable) | |
458 { | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
459 // Progress game animation clock |
25 | 460 gameClock++; |
9 | 461 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
462 // Animate components |
25 | 463 lauta.animate(gameClock); |
54 | 464 lauta.nextPiece.animate(gameClock); |
9 | 465 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
466 // Repaint with a frame limiter |
25 | 467 if (gameClock % 3 == 1) |
24 | 468 { |
10 | 469 repaint(); |
25 | 470 gameFrames++; |
24 | 471 } |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
472 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
473 // Sleep for a moment |
9 | 474 try { |
475 Thread.sleep(10); | |
476 } | |
477 catch (InterruptedException x) { | |
478 } | |
8 | 479 } |
480 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
481 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
482 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
|
483 { |
51 | 484 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
|
485 { |
51 | 486 super(x, y, KeyEvent.VK_ESCAPE, font1, "Uusi peli"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
487 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
488 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
489 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
|
490 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
491 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
492 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
493 } |
50 | 494 |
495 class BtnSwapPiece extends IDMButton | |
496 { | |
51 | 497 public BtnSwapPiece(float x, float y) |
50 | 498 { |
51 | 499 super(x, y, KeyEvent.VK_SPACE, font1, "Vaihda"); |
50 | 500 } |
501 | |
502 public void clicked() | |
503 { | |
54 | 504 lauta.pieceSwapCurrent(); |
50 | 505 } |
506 } | |
0 | 507 } |