Mercurial > hg > ristipolku
diff game/Engine.java @ 27:26adc2827983
More work on the internals.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 01 Feb 2011 20:38:19 +0200 |
parents | 3d4cc47df31a |
children | 60a4579a79df |
line wrap: on
line diff
--- a/game/Engine.java Tue Feb 01 19:18:25 2011 +0200 +++ b/game/Engine.java Tue Feb 01 20:38:19 2011 +0200 @@ -31,6 +31,12 @@ this.outX = outX; this.outY = outY; } + + public void print() + { + System.out.print("PathInfo: inP="+in+", inX="+inX+", inY="+inY+"\n"); + System.out.print(" outP="+out+", outX="+outX+", outY="+outY+"\n"); + } } /* @@ -129,14 +135,6 @@ return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); } - private Piece getPiece(int x, int y) - { - if (x >= 0 && x < boardSize && y >= 0 && y < boardSize) - return board[x][y]; - else - return null; - } - public void pieceRotate(boolean dir) { if (current != null) @@ -146,20 +144,54 @@ public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark) { int x = startX, y = startY; - int point = -1; - - Piece curr = getPiece(startX, startY); - if (curr == null) - return null; + int point = startPoint; + Piece curr = board[x][y]; -/* - while (curr != null) + do { -// curr.(true); -// elements.spawn("", ); + if (x >= 0 && x < boardSize && y >= 0 && y < boardSize) + { + curr = board[x][y]; + if (curr == null) + break; + + if (curr.getType() == PieceType.START) + { + // Hit center starting piece + return null; + } + else + { + // Mark, if needed + if (mark) + { + curr.setType(PieceType.LOCKED); + curr.setActiveConnection(point); + } + + // Get next piece + point = curr.getConnection(point); + switch (point) + { + case 0: y--; break; + case 1: y--; break; + case 2: x++; break; + case 3: x++; break; + case 4: y++; break; + case 5: y++; break; + case 6: x--; break; + case 7: x--; break; + } + } + } + else + { + // Outside of the board + return null; + } } -*/ - + while (curr != null); + return new PathInfo(startPoint, startX, startY, point, x, y); } @@ -172,6 +204,11 @@ if (i != null) { + System.out.print("moveX="+moveX+", moveY="+moveY+", movePoint="+movePoint+"\n"); + i.print(); + moveX = i.outX; + moveY = i.outY; + movePoint = i.out; } } @@ -186,7 +223,10 @@ if (i != null) board[moveX][moveY] = current; else + { + System.out.print("pieceFinishTurn(): Game Over!\n"); flagGameOver = true; + } } } }