Skip to content
Snippets Groups Projects
Commit 290af6d4 authored by Tamas Bunth's avatar Tamas Bunth
Browse files

cannot set element to null in foreach

parent adc8bd0b
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,7 @@ public class Portal extends DefaultElement { ...@@ -82,6 +82,7 @@ public class Portal extends DefaultElement {
public boolean leave(Portal portal) { public boolean leave(Portal portal) {
if(portal.equals(this)) { if(portal.equals(this)) {
this.setFieldNeigboursBack(); this.setFieldNeigboursBack();
this.otherSide = null;
this.getField().addToRemove(this); this.getField().addToRemove(this);
return true; return true;
}else { }else {
...@@ -90,11 +91,16 @@ public class Portal extends DefaultElement { ...@@ -90,11 +91,16 @@ public class Portal extends DefaultElement {
} }
/**
* Reset the linkage of Fields
*/
private void setFieldNeigboursBack() private void setFieldNeigboursBack()
{ {
if(otherSide != null) {
this.getField().getNeighbour(side).setNeighbour(Direction.convertToInverse(side), this.getField()); this.getField().getNeighbour(side).setNeighbour(Direction.convertToInverse(side), this.getField());
otherSide.getField().getNeighbour(otherSide.side).setNeighbour(Direction.convertToInverse(otherSide.side), otherSide.getField()); otherSide.getField().getNeighbour(otherSide.side).setNeighbour(Direction.convertToInverse(otherSide.side), otherSide.getField());
} }
}
......
...@@ -72,9 +72,10 @@ public class Wall extends DefaultElement{ ...@@ -72,9 +72,10 @@ public class Wall extends DefaultElement{
{ {
if(portal == null) if(portal == null)
return false; return false;
for (Portal myportal : this.portals) { for (int i = 0; i < portals.length; i++) {
if(portal.equals(myportal)) { if(portal.equals(portals[i])) {
myportal = null; System.out.println("falrol le");
portals[i] = null;
} }
} }
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment