Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void deleteWall(int y, int x) {
- for (Wall wall : getWalls()) {
- if (wall.getX() == x && wall.getY() == y && wall.isAlive()) {
- wall.destroyWall();}
- while(wall.getVisited()==false) {
- rekursion(y, x);
- }
- }
- }
- public void markVisited(int y, int x) {
- for (Wall wall : getWalls()) {
- if (wall.getX() == x && wall.getY() == y) {
- wall.setVisited();
- }
- }
- }
- private void rekursion(int y, int x) {
- markVisited(y - 1, x);
- markVisited(y + 1, x);
- markVisited(y, x - 1);
- markVisited(y, x + 1);
- int i = (int) (Math.random() * 4);
- switch (i) {
- case 0:
- if (y - 1 >= 0) {
- y--;
- deleteWall(y, x);
- }
- break;
- case 1:
- if (y + 1 <= this.y) {
- y++;
- deleteWall(y, x);
- }
- break;
- case 2:
- if (x - 1 >= 0) {
- x--;
- deleteWall(y, x);
- }
- break;
- case 3:
- if (x + 1 <= this.x) {
- x++;
- deleteWall(y, x);
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement