public void smooth(Map map) {
    System.out.println("Smoothing all cells");
    for (int x = 1; x <= map.getWidth(); x++) {
      for (int y = 1; y <= map.getHeight(); y++) {
        Cell cell = map.getCell(x, y);
        final Terrain terrain = cell.getTerrain();

        TerrainFacing facing =
            getFacing(
                terrain.isSame(cell.getCellAbove().getTerrain()),
                terrain.isSame(cell.getCellRight().getTerrain()),
                terrain.isSame(cell.getCellBeneath().getTerrain()),
                terrain.isSame(cell.getCellLeft().getTerrain()));

        terrain.setFacing(facing);
      }
    }
  }
Esempio n. 2
0
  @Override
  public void start(Stage primaryStage) {

    // generated layout to be converted to GUI
    File sampleLayoutXMLFile =
        new File("MapLayout.xml"); // added to see functionality with xml file
    Map layout = new Map(sampleLayoutXMLFile); // <==
    // Map layout = new Map();

    // main container for GUI: has areas for top/bottom/left/right/center
    BorderPane root = new BorderPane();

    // container for map GUI
    GridPane map = new GridPane();
    map.setPadding(new Insets(MAP_PADDING));
    map.setHgap(CELL_GAP);
    map.setVgap(CELL_GAP);

    // array of cells to be added to map GUI
    StackPane cells[][] = new StackPane[layout.getWidth()][layout.getHeight()];

    for (int row = 0; row < layout.getHeight(); row++) {
      for (int col = 0; col < layout.getWidth(); col++) {
        // create the cell's appearance
        cells[row][col] = buildCell(layout.getCell(row, col));
        // this is the correct way to have it
        // https://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html#add(javafx.scene.Node, int, int)
        map.add(cells[row][col], row, col);
      }
    }

    root.setCenter(map);

    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Clean Sweep Vacuum");
    primaryStage.show();
  }
 public void putTerrainOnCell(Map map, int x, int y, int terrainType) {
   final Cell cell = map.getCell(x, y);
   final Terrain terrain = terrainFactory.create(terrainType, cell);
   cell.changeTerrain(terrain);
 }