Advertisement
Ajtak

Untitled

Dec 25th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1.    private void recompute(int[][] matrix) {
  2.         boolean top = currRow > 0 && matrix[currRow - 1][currCol] == 0;
  3.         boolean right = currCol < matrix[currRow].length - 1 && matrix[currRow][currCol + 1] == 0;
  4.  
  5.         boolean bottom = currRow + 1 < matrix.length - 1 && matrix[currRow + 1][currCol] == 0;
  6.         boolean left = currCol > 0 && matrix[currRow][currCol - 1] == 0;
  7.  
  8.  
  9.         if (bottom) {
  10.             currRow++;
  11.         } else if (top) {
  12.             currRow--;
  13.         } else if (left) {
  14.             currCol--;
  15.         } else if (right) {
  16.             currRow++;
  17.         }
  18.     }
  19.  
  20.     public void redrawPath(int[][] matrix) {
  21.  
  22.         recompute(matrix);
  23.  
  24.         Timeline timeline;
  25.         KeyFrame frame = new KeyFrame(Duration.millis(1000), e -> {
  26.             recompute(matrix);
  27.         }, new KeyValue(eminem.xProperty(), currCol * Constants.BLOK_SIZE),
  28.                 new KeyValue(eminem.yProperty(), currRow * Constants.BLOK_SIZE));
  29.  
  30.         timeline = new Timeline(frame);
  31.         timeline.setCycleCount(Timeline.INDEFINITE);
  32.         timeline.play();
  33.  
  34.         //Neighbours n = new Neighbours(top, right, bottom, left);
  35.  
  36.         //System.out.println(top + " - " + right + " " + bottom + " " + left);
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement