Mercurial > hg > ristipolku
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:6bf4675e2d96 | 54:cc7943cd7f2d |
---|---|
61 public static final int boardSize = 9; | 61 public static final int boardSize = 9; |
62 public static final int boardMiddle = 4; | 62 public static final int boardMiddle = 4; |
63 Piece[][] board; | 63 Piece[][] board; |
64 | 64 |
65 public boolean flagGameOver; | 65 public boolean flagGameOver; |
66 | 66 |
67 Piece currPiece; | 67 public Piece currPiece, nextPiece; |
68 int currX, currY, currPoint; | 68 int currX, currY, currPoint; |
69 | 69 |
70 int score; | 70 int score; |
71 | 71 |
72 SoundManager soundManager; | 72 SoundManager soundManager; |
80 | 80 |
81 currX = boardMiddle; | 81 currX = boardMiddle; |
82 currY = boardMiddle; | 82 currY = boardMiddle; |
83 currPoint = 0; | 83 currPoint = 0; |
84 | 84 |
85 nextPiece = new Piece(PieceType.ACTIVE); | |
85 pieceFinishTurn(); | 86 pieceFinishTurn(); |
86 | 87 |
87 flagGameOver = false; | 88 flagGameOver = false; |
88 score = 0; | 89 score = 0; |
89 | 90 |
140 case 6: currX--; break; | 141 case 6: currX--; break; |
141 case 7: currX--; break; | 142 case 7: currX--; break; |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
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 | |
145 public boolean pieceCheck(Piece piece) | 160 public boolean pieceCheck(Piece piece) |
146 { | 161 { |
147 if (piece == null) | 162 if (piece == null) |
148 { | 163 { |
149 // Create new piece | 164 // Create new piece |
162 } | 177 } |
163 else | 178 else |
164 { | 179 { |
165 // Start piece as first piece means game is starting | 180 // Start piece as first piece means game is starting |
166 pieceMoveTo(currPoint); | 181 pieceMoveTo(currPoint); |
167 currPiece = new Piece(PieceType.ACTIVE); | 182 pieceCreateNew(); |
168 board[currX][currY] = currPiece; | 183 board[currX][currY] = currPiece; |
169 return true; | 184 return true; |
170 } | 185 } |
171 } | 186 } |
172 | 187 |
211 } | 226 } |
212 } | 227 } |
213 | 228 |
214 public boolean keyPressed(KeyEvent e) | 229 public boolean keyPressed(KeyEvent e) |
215 { | 230 { |
231 if (flagGameOver) | |
232 return false; | |
233 | |
216 switch (e.getKeyCode()) | 234 switch (e.getKeyCode()) |
217 { | 235 { |
218 case KeyEvent.VK_LEFT: | 236 case KeyEvent.VK_LEFT: |
219 case KeyEvent.VK_UP: | 237 case KeyEvent.VK_UP: |
220 pieceRotate(Piece.RotateDir.LEFT); | 238 pieceRotate(Piece.RotateDir.LEFT); |
354 } | 372 } |
355 | 373 |
356 // Background image, pieces | 374 // Background image, pieces |
357 g2.drawImage(lautaBGScaled, 0, 0, null); | 375 g2.drawImage(lautaBGScaled, 0, 0, null); |
358 lauta.paint(g2, 90, 140, 65); | 376 lauta.paint(g2, 90, 140, 65); |
377 lauta.nextPiece.paint(g2, 830, 325, 90); | |
359 widgets.paint(g2); | 378 widgets.paint(g2); |
360 | 379 |
361 // Scores, etc | 380 // Scores, etc |
362 g2.setFont(font1); | 381 g2.setFont(font1); |
363 g2.setPaint(Color.white); | 382 g2.setPaint(Color.white); |
440 // Progress game animation clock | 459 // Progress game animation clock |
441 gameClock++; | 460 gameClock++; |
442 | 461 |
443 // Animate components | 462 // Animate components |
444 lauta.animate(gameClock); | 463 lauta.animate(gameClock); |
464 lauta.nextPiece.animate(gameClock); | |
445 | 465 |
446 // Repaint with a frame limiter | 466 // Repaint with a frame limiter |
447 if (gameClock % 3 == 1) | 467 if (gameClock % 3 == 1) |
448 { | 468 { |
449 repaint(); | 469 repaint(); |
479 super(x, y, KeyEvent.VK_SPACE, font1, "Vaihda"); | 499 super(x, y, KeyEvent.VK_SPACE, font1, "Vaihda"); |
480 } | 500 } |
481 | 501 |
482 public void clicked() | 502 public void clicked() |
483 { | 503 { |
504 lauta.pieceSwapCurrent(); | |
484 } | 505 } |
485 } | 506 } |
486 } | 507 } |