Mercurial > hg > ristipolku
comparison game/Engine.java @ 35:aa15b2c556b4
Add comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 17 Feb 2011 03:40:01 +0200 |
parents | e480579cc460 |
children | 3dc5ae9f1c80 |
comparison
equal
deleted
inserted
replaced
34:6f6c551cc14c | 35:aa15b2c556b4 |
---|---|
229 return new PathInfo(startPoint, startX, startY, point, x, y); | 229 return new PathInfo(startPoint, startX, startY, point, x, y); |
230 } | 230 } |
231 | 231 |
232 public void pieceFinishTurn() | 232 public void pieceFinishTurn() |
233 { | 233 { |
234 // Do we have a piece? | |
234 if (current != null) | 235 if (current != null) |
235 { | 236 { |
237 // Yes, place and lock it | |
236 current.setType(PieceType.LOCKED); | 238 current.setType(PieceType.LOCKED); |
237 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 239 PathInfo i = resolvePath(moveX, moveY, movePoint, true); |
238 | 240 |
239 if (i != null) | 241 if (i != null) |
240 { | 242 { |
244 moveY = i.outY; | 246 moveY = i.outY; |
245 movePoint = i.out; | 247 movePoint = i.out; |
246 } | 248 } |
247 } | 249 } |
248 | 250 |
251 // Create a new piece | |
249 current = new Piece(PieceType.ACTIVE); | 252 current = new Piece(PieceType.ACTIVE); |
253 | |
254 // Find a place for it | |
250 if (isEmpty(moveX, moveY)) | 255 if (isEmpty(moveX, moveY)) |
251 { | 256 { |
257 // Current position is empty, use it | |
252 board[moveX][moveY] = current; | 258 board[moveX][moveY] = current; |
253 } | 259 } |
254 else | 260 else |
255 { | 261 { |
262 // Resolve path | |
256 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 263 PathInfo i = resolvePath(moveX, moveY, movePoint, true); |
257 if (i != null) | 264 if (i != null) |
258 board[moveX][moveY] = current; | 265 board[moveX][moveY] = current; |
259 else | 266 else |
260 { | 267 { |
268 // Path ended up center/gameboard walls - it's game over, man | |
261 System.out.print("pieceFinishTurn(): Game Over!\n"); | 269 System.out.print("pieceFinishTurn(): Game Over!\n"); |
262 flagGameOver = true; | 270 flagGameOver = true; |
263 } | 271 } |
264 } | 272 } |
265 } | 273 } |
463 case KeyEvent.VK_ENTER: | 471 case KeyEvent.VK_ENTER: |
464 lauta.pieceFinishTurn(); | 472 lauta.pieceFinishTurn(); |
465 snd(Sound.PIECE_PLACED).stop(); | 473 snd(Sound.PIECE_PLACED).stop(); |
466 snd(Sound.PIECE_PLACED).play(); | 474 snd(Sound.PIECE_PLACED).play(); |
467 break; | 475 break; |
476 | |
477 case KeyEvent.VK_ESCAPE: | |
478 break; | |
468 } | 479 } |
469 } | 480 } |
470 | 481 |
471 public void run() | 482 public void run() |
472 { | 483 { |