mirror of
https://github.com/OpenLiberty/liberty-bikes.git
synced 2025-01-18 10:23:58 +08:00
fix trail
This commit is contained in:
parent
bdba9ca086
commit
4dc15ab6e0
@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.libertybikes.game.core;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
@ -156,21 +157,26 @@ public class Player {
|
||||
}
|
||||
|
||||
trail.add(new TrailPosition(x + 1, y + 1));
|
||||
|
||||
boolean first = true;
|
||||
if (trail.size() > 2) {
|
||||
TrailPosition trailP = trail.remove();
|
||||
trailPosX = trailP.x;
|
||||
trailPosY = trailP.y;
|
||||
s[trailPosX][trailPosY] = GameBoard.TRAIL_SPOT_TAKEN;
|
||||
s[trailPosX2][trailPosY2] = GameBoard.TRAIL_SPOT_TAKEN;
|
||||
if (lastDirection != direction) {
|
||||
TrailPosition trailP2 = trail.remove();
|
||||
trailPosX2 = trailP2.x;
|
||||
trailPosY2 = trailP2.y;
|
||||
s[trailPosX2][trailPosY2] = (short) (GameBoard.PLAYER_SPOT_TAKEN + playerNum);
|
||||
Iterator<TrailPosition> it = trail.iterator();
|
||||
while (it.hasNext()) {
|
||||
TrailPosition tp = it.next();
|
||||
if (!withinOneSquare(tp)) {
|
||||
if (first) {
|
||||
s[tp.x][tp.y] = GameBoard.TRAIL_SPOT_TAKEN;
|
||||
trailPosX = tp.x;
|
||||
trailPosY = tp.y;
|
||||
it.remove();
|
||||
first = false;
|
||||
} else {
|
||||
trailPosX2 = trailPosX;
|
||||
trailPosY2 = trailPosY;
|
||||
s[tp.x][tp.y] = GameBoard.TRAIL_SPOT_TAKEN;
|
||||
trailPosX2 = tp.x;
|
||||
trailPosY2 = tp.y;
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,6 +185,13 @@ public class Player {
|
||||
return isAlive();
|
||||
}
|
||||
|
||||
private boolean withinOneSquare(TrailPosition trail) {
|
||||
if (Math.abs(trail.x - (x + 1)) <= 1 && Math.abs(trail.y - (y + 1)) <= 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkCollision(short[][] board, int x, int y) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
|
Loading…
Reference in New Issue
Block a user