Using a String to Instantiate an object in Greenfoot?

117 Views Asked by At

So, as part of my college coursework we are working in teams to develop simplistic games in Greenfoot, partly to develop on teamwork skills, and partly for actual programming.
Our game features a perlin/simplex generated map to render tessellated terrain tiles for our gameplay, however I need a way to reference the tiles individually, in order for a given tile to interact with it's neighbours.
Is there an easy way I can instantiate a worldTile object by passing a string such as their x/y coordinates (eg ter_12_142)? Or is there a simpler method to go about this?

Here's my code for placing tiles in the world;

private void tilePlacement() {

  for (int y = 1; y < rows - 1; y++) {
    for (int x = 2; x < cols - (cols / 4); x++) {

      int w = (getColor(noise[x][y][0]));
      int isAForest = (isForest(noise[x][y][1]));

      addObject(new worldTile(w, isAForest), x * scl, y * scl);

    }
  }
}
0

There are 0 best solutions below