Adding reach for steel block using BFS

master
bob 2022-06-15 14:54:21 -04:00
parent 35fa4639e1
commit 537e3939ea
2 changed files with 28 additions and 6 deletions

View File

@ -348,12 +348,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
// increment sprite image to be used and keeps it below 12 // increment sprite image to be used and keeps it below 12
playerFrame = (playerFrame + 1) % 11; playerFrame = (playerFrame + 1) % 11;
playerFrameCounter -= 5; playerFrameCounter -= 5;
// if the player has moved enough to justify a frame change, a new save will also be made // // if the player has moved enough to justify a frame change, a new save will also be made
try { // try {
FileManager.writeObjectToFile("local/game_state", new ArrayList()); // this is placeholder, replace with this // FileManager.writeObjectToFile("local/game_state", new ArrayList()); // this is placeholder, replace with this
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} }
} }
repaint(); repaint();

View File

@ -303,8 +303,30 @@ public class Player extends GenericSprite {
boolean[][]vis = new boolean[1000][18]; boolean[][]vis = new boolean[1000][18];
LinkedList<Integer> xx = new LinkedList<>(); LinkedList<Integer> xx = new LinkedList<>();
LinkedList<Integer> yy = new LinkedList<>(); LinkedList<Integer> yy = new LinkedList<>();
xx.add(pX);
yy.add(pY);
dis[pX][pY] = 0; dis[pX][pY] = 0;
vis[pX][pY] = true; vis[pX][pY] = true;
while(!xx.isEmpty()){
int tempX = xx.poll();
int tempY = yy.poll();
for(int[]a: check){
try{
int newX = tempX + a[0];
int newY = tempY + a[1];
if(dis[tempX][tempY]+1<(Math.min(3,dis[newX][newY]))){
dis[newX][newY] = dis[tempX][tempY]+1;
xx.add(newX);
yy.add(newY);
}
} catch(Exception e){
}
}
}
if(dis[pX][pY]<=3){
return true;
}
return false; return false;
} }
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {