如何使用二维数组存储坐标?(How to store co-ordinates using a two dimensional array?)
我正在做一个涉及二维数组的项目。 该项目涉及一个从左上角移动到右下角的点。 我现在正在做的是制作一个可能的XMoves数组和一个可能的YMoves数组。 我想知道是否有更好的方法来定义二维数组的坐标。 以下是我所拥有的。
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};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};最满意答案
您可以使用Point类。
不是将可能的索引存储在单独的数组中,而是将它们作为Points集合存储在一个数组中。
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.
更多推荐
发布评论