/** * Gets a random space on the map that is open space * * @return Random empty coordinates * @author Alex */ public Point getUnoccupiedPosition() { Point position = new Point(); // Do while empty space not found do { position.x = random.nextInt(map.getXSize()); position.y = random.nextInt(map.getYSize()); } while (map.getCells()[position.y].toCharArray()[position.x] != ' ' && !isBugAtPosition(position)); return position; }
/** * Prints the map on screen with all the bugs inside * * @param printBoundaries * Whether to indicate the boundary of the map by pipes and dashs * @author Alex */ public void printMap(boolean printBoundaries) { if (printBoundaries) map.printBorder(); // Conver the map to an array of strings to insert the bugs in ArrayList<String> mapList = new ArrayList<String>(); // Iterate rows for (String row : map.getCells()) { String mapRow = ""; if (printBoundaries) mapRow += "|"; mapRow += row; if (printBoundaries) mapRow += "|"; mapList.add(mapRow); } // Insert bugs in map for (ABug bug : bugs) { // Get the row char[] row = mapList.get(bug.getPosition().y).toCharArray(); // Insert the bug row[bug.getPosition().x + 1] = bug.getSymbol(); mapList.set(bug.getPosition().y, new String(row)); } // Print mapList for (String line : mapList) System.out.println(line); if (printBoundaries) map.printBorder(); }