Making a 2d arraylist
in
Programming Questions
•
3 months ago
Hi all and firstly thanks in advance :)
Now for some context, I'm making a game which requires the random generation of blocks to a point on the grid, I currently have all possible coordinates in a 2d array and processing randomly chooses a coordinate. Simple enough however the chosen coordinate is not removed from the array so it is possible blocks can appear on top of each other which doesn't work for the game. Having tried subset() to remove the chosen coordinate, I discovered I would need an arraylist. This is my 2d array:
int[][] grid ={ {0, 0}, {0, 50}, {0, 100}, {0, 150}, {0, 200}, {0, 250}, {0, 300}, {0, 350},
{50, 0}, {50, 50}, {50, 100}, {50, 150}, {50, 200}, {50, 250}, {50, 300}, {50, 350},
{100, 0}, {100, 50}, {100, 100}, {100, 150}, {100, 200}, {100, 250}, {100, 300}, {100, 350},
{150, 0}, {150, 50}, {150, 100}, {150, 150}, {150, 200}, {150, 250}, {150, 300}, {150, 350},
{200, 0}, {200, 50}, {200, 100}, {200, 150}, {200, 200}, {200, 250}, {200, 300}, {200, 350},
{250, 0}, {250, 50}, {250, 100}, {250, 150}, {250, 200}, {250, 250}, {250, 300}, {250, 350} };
I have a block function and using the following I can reference a coordinate:
int block1 = int(random(grid.length));
int j = 0;
int k = 1;
myBlock1 = new Block(color(colours[c1]), grid[block1][j], grid[block1][k]);
So I need to make this into a 2d arraylist so that I can remove the chosen coordinate from the array, any ideas on the syntax for the 2d arraylist and how i reference the coordinates?
Or if its possible to give me help on removing the used coordinates from the original array rather than using an arraylist?
Now for some context, I'm making a game which requires the random generation of blocks to a point on the grid, I currently have all possible coordinates in a 2d array and processing randomly chooses a coordinate. Simple enough however the chosen coordinate is not removed from the array so it is possible blocks can appear on top of each other which doesn't work for the game. Having tried subset() to remove the chosen coordinate, I discovered I would need an arraylist. This is my 2d array:
int[][] grid ={ {0, 0}, {0, 50}, {0, 100}, {0, 150}, {0, 200}, {0, 250}, {0, 300}, {0, 350},
{50, 0}, {50, 50}, {50, 100}, {50, 150}, {50, 200}, {50, 250}, {50, 300}, {50, 350},
{100, 0}, {100, 50}, {100, 100}, {100, 150}, {100, 200}, {100, 250}, {100, 300}, {100, 350},
{150, 0}, {150, 50}, {150, 100}, {150, 150}, {150, 200}, {150, 250}, {150, 300}, {150, 350},
{200, 0}, {200, 50}, {200, 100}, {200, 150}, {200, 200}, {200, 250}, {200, 300}, {200, 350},
{250, 0}, {250, 50}, {250, 100}, {250, 150}, {250, 200}, {250, 250}, {250, 300}, {250, 350} };
I have a block function and using the following I can reference a coordinate:
int block1 = int(random(grid.length));
int j = 0;
int k = 1;
myBlock1 = new Block(color(colours[c1]), grid[block1][j], grid[block1][k]);
So I need to make this into a 2d arraylist so that I can remove the chosen coordinate from the array, any ideas on the syntax for the 2d arraylist and how i reference the coordinates?
Or if its possible to give me help on removing the used coordinates from the original array rather than using an arraylist?
1