我正在开发一个俄罗斯方 block 游戏,并且我在 xml 文件中以下列格式保存方 block 图。
<block column="2">101011</block>
然后我将这个 xml 解析为一维数组,如下所示
boolean[] bitmap=new boolean[]{true,false,true,false,true,true};//101011 在 java 中的 boolean 值
然后在绘制俄罗斯方 block 时使用列号和这个一维数组来计算每个 block 的坐标。 然后显示“L” block
10
10
11
现在...我想旋转这些 block ...我需要的是:(对于 ccw)
101011
到
001111
和列号 2 到 3
最佳答案
尝试使用此代码遍历二维数组,以便创建所需的一维数组:
int[][] array = new int[][] { { 1, 0 }, { 1, 0 }, { 1, 1 } };
int[] newArray = new int[6];
int index = 0;
// Populating 1D array.
for (int i = array[0].length; i > 0; i--)
for (int j = 0; j < array.length; j++)
newArray[index++] = array[j][i - 1];
// See the contents of 1D array.
for (int i = 0; i < newArray.length; i++)
System.out.println(newArray[i]);
关于java - 如何旋转打包到一维数组中的二维矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9599764/