Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. public void deleteWall(int y, int x) {
  2.         for (Wall wall : getWalls()) {
  3.             if (wall.getX() == x && wall.getY() == y && wall.isAlive()) {
  4.                 wall.destroyWall();}
  5.                 while(wall.getVisited()==false) {
  6.                 rekursion(y, x);
  7.             }
  8.         }
  9.     }
  10.  
  11.     public void markVisited(int y, int x) {
  12.         for (Wall wall : getWalls()) {
  13.             if (wall.getX() == x && wall.getY() == y) {
  14.                 wall.setVisited();
  15.             }
  16.         }
  17.     }
  18.  
  19.     private void rekursion(int y, int x) {
  20.         markVisited(y - 1, x);
  21.         markVisited(y + 1, x);
  22.         markVisited(y, x - 1);
  23.         markVisited(y, x + 1);
  24.         int i = (int) (Math.random() * 4);
  25.         switch (i) {
  26.         case 0:
  27.             if (y - 1 >= 0) {
  28.                 y--;
  29.                 deleteWall(y, x);
  30.             }
  31.             break;
  32.         case 1:
  33.             if (y + 1 <= this.y) {
  34.                 y++;
  35.                 deleteWall(y, x);
  36.             }
  37.             break;
  38.         case 2:
  39.             if (x - 1 >= 0) {
  40.                 x--;
  41.                 deleteWall(y, x);
  42.             }
  43.             break;
  44.         case 3:
  45.             if (x + 1 <= this.x) {
  46.                 x++;
  47.                 deleteWall(y, x);
  48.             }
  49.             break;
  50.         }
  51.        
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement