@Override public void tankMove(Coordinates delta) { for (int i = 0; i < this.elements.length; i++) { Movable toMove = null; try { toMove = (Movable) this.elements[i]; } catch (ClassCastException e) { continue; } if (toMove == null) continue; if (toMove.getType() != Type.TANK) continue; if (!(toMove.isAlive())) continue; try { BoundingBox toMoveNextBb = toMove.getArea().translate(delta); BoundingBox gridBb = new BoundingBox(new Coordinates(0, 0), this.maxSize); BoundingBox intersection = toMoveNextBb.intersection(gridBb); if (!(intersection.equals(toMoveNextBb))) return; toMove.move(delta); } catch (NegativeSizeException e) { // ignore this, nothing is moved } } }