/** * Sets a new grid for this world. Occupants are transferred from the old world to the new. * * @param newGrid the new grid */ public void setGrid(Grid<T> newGrid) { Grid<T> oldGrid = world.getGrid(); Map<Location, T> occupants = new HashMap<Location, T>(); for (Location loc : oldGrid.getOccupiedLocations()) occupants.put(loc, world.remove(loc)); world.setGrid(newGrid); for (Location loc : occupants.keySet()) { if (newGrid.isValid(loc)) world.add(loc, occupants.get(loc)); } display.setGrid(newGrid); repaint(); }