Reputation: 64
I am doing a project involving a two dimensional array. The project involves a dot that moves from the top left corner to the bottom right corner. What I am doing right now is making an array of possibleXMoves and an array of possibleYMoves. I was wondering if there was a better way to define coordinates for a two dimensional array. Below is what I have.
int moveX1 = x + 1;
int moveX2 = x + 1;
int moveX3 = x + 1;
int moveX4 = x;
int moveX5 = x - 1;
int moveX6 = x - 1;
int moveX7 = x - 1;
int moveX8 = x;
int [] possibleXIndexes = {moveX1, moveX2, moveX3, moveX4, moveX5, moveX6, moveX7, moveX8};
int moveY1 = y - 1;
int moveY2 = y;
int moveY3 = y + 1;
int moveY4 = y + 1;
int moveY5 = y + 1;
int moveY6 = y;
int moveY7 = y - 1;
int moveY8 = y - 1;
int [] possibleYIndexes = {moveY1, moveY2, moveY3, moveY4, moveY5, moveY6, moveY7, moveY8};
Upvotes: 0
Views: 58
Reputation: 1640
You could use the Point class.
Instead of storing the possible indexes in separate arrays, just store them in one as a collection of Points.
Upvotes: 1