class StaticField/*************************************************************/ { float value; float maxDistance; float[][]sField; ArrayList doorList; ObstacleField oField; ArrayList cellsToStartCheck; ArrayList cellsWhichHaveToBeChecked; /************constructor************************************/ StaticField(int gridColumns, int gridLines, ArrayList doorList, ObstacleField oField ) { this.oField=oField; this.doorList=doorList; sField = new float[gridColumns][gridLines]; if (doorList.size()==0) { for (int i=0; imaxDistance) { maxDistance=dist[i][k]; } } } } for (int i=0; i 0 && uncheckedCellsInLastRound!=neighborCells.size()) { // speichern der anzahl ungeprüfter zellen // stellt sicher, dass keine endlosschleife entsteht uncheckedCellsInLastRound = neighborCells.size(); // liste für die Überprüfung im nächsten durchgang ArrayList cellsToCheckNext = new ArrayList(); // alle zellen, die jetzt überprüft werden sollen while (startCells.size() > 0) { // nimmt die erste zelle aus der liste Cell cell = (Cell) startCells.remove(0); // nimmt alle nachbarn dieser zelle ArrayList neighbours = cell.getNeighbours(); for (int i = 0; i < neighbours.size(); i++) { Cell neighbour = (Cell) neighbours.get(i); // wenn der nachbar noch nicht überprüft wurde if (neighbour.isInList(neighborCells)) { // berechnung türabstand float distance = cell.getDistanceToDoor() + 1; neighbour.setDistanceToDoor(distance); // diese zelle gilt als geprüft neighborCells.remove(neighbour); // ihre nachbarn werden aber im nächsten durchgang gechecked cellsToCheckNext.add(neighbour); } } } // cellsToCheck ist jetzt leer // alle zellen aus dem 'nachbarCheck' sollen im nächsten // durchgang gechecked werden startCells.addAll(cellsToCheckNext); } } Cell[][] generateCellsWithConnections() //*********************************************************** { Cell[][] cellArray = new Cell[gridColumns][gridLines]; for (int i=0; i obstacle // dann überspringe diese runde im 'k'-loop if (cellArray[i][k] == null) continue; Cell cell = cellArray[i][k]; // loop through directions east, west, north, south // add cells to the neighbour list int[][] coord = { {-1, 0}, { 1, 0}, { 0, -1}, { 0, 1} }; for (int m=0; m= cellArray.length) || (y < 0) || (y >= cellArray[0].length); if ( !outOfBounds ) { if (cellArray[x][y] != null) { cell.addNeighbour(cellArray[x][y]); } } } } } return cellArray; } void printlnValues()//********************************************************** { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(3); nf.setMinimumFractionDigits(3); for(int i=0; i