You can create a basic pojo like this:
public class Block {
private int x;
private int y;
public Block(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
You can then create a Maze class for example:
public class Maze {
public void addBlock(Block block) {
// your logic here
}
}
The data structure to use for storing Block objects depends of the situation. I recommend a HashMap with a String key based on coordinates (if it has irregular shape) or an array/List.
HashMap version:
private Map<String, Block> blocks; // ...
public void addBlock(Block block) {
blocks.put(block.getX()+","+block.getY(), block);
}
array version:
private Block[][] blocks; // ...
public void addBlock(Block block) {
blocks[block.getX()][block.getY()] = block;
}
You can see that the advantage of the HashMap version is that it is dynamic. You have to initialize an array with default values.
Blockand create a constructor that takes the two parameters...addBlockclass but don't know how to construct it?