0

我试图弄清楚如何将这些矩形坐标放入一个数组中(使用循环),但我无法让它们正确。数组中的值默认为“false”。例如,如果坐标为 0,则 24 blockCoords[0][1] 应该为“true”。对不起我的英语,我不是母语:P

boolean[ ][ ] blockCoords = new boolean[20][10];//the array

//added the code to create the array
  private void createArray() {
        for(int i=0;i<20;i++) {
             for(int j=0;j<10;j++) {
                  blockCoords[i][j]=false;
          }
      }
  }
//b is the block
int y1 = b.getY();//get the coordinates of the top of a block
int y2 = b.getHeight();//the height of a block
int x1 = b.getX();
int x2 = b.getWidth();
int numHorizontal = 10-((240-x2)/24);//calculates how many blocks there are - 24 is the width and the height of a block - 240/480 are the dimensions
int numVertical = 20-((480-y2)/24);
int col=10-((240-x1)/24);//in which column does the block's coordinates start in
int row=((480-y1)/24)-1;// same for the row
4

2 回答 2

0

如果我正确理解您的问题:

for(int i = row; i < numVertical; i++){
    for(int j = col; j < numHorizontal; j++){
        blockCoords[i][j] = true;
    }
}
于 2013-04-16T20:57:25.000 回答
0

您永远不会为数组 blockCoords 分配任何值,因此它永远不会假定除 false 之外的任何其他值。我怀疑您打算使用 x 和 y 坐标为数组分配值。

于 2013-04-16T20:52:32.947 回答