俄罗斯方块java
id*iWidthGrid][2];
//转换,把方块内有效部分的坐标都转换成容器内的坐标,然后返回.
for(int i=0;i<iHeightGrid;i++)
for(int j=0;j<iWidthGrid;j++)
if(aryDiamonds[i][j]==1)
{
rtnRowColNos[i*iWidthGrid+j][0]=referPoint[0]+i;
rtnRowColNos[i*iWidthGrid+j][1]=referPoint[1]+j;
}
else //把方块中不用显示的部分的行号和列号设为-1,便于区分.
{
rtnRowColNos[i*iWidthGrid+j][0]=-1;
rtnRowColNos[i*iWidthGrid+j][1]=-1;
}
return(rtnRowColNos);
}
//返回判定向左移动时判定接触的方块部分的行号和列号,数组中元素存放的顺序无要求.
public int[][] leftTouchGrids()
{
int[][] rtnRowColNos=new int[iHeightGrid][2]; //第1维是接触面所占格子的数量,第2维的第1,2个元素是格子相对于容器的坐标.
//这里默认方块的接触面是连续的没有空缺.
for(int i=0;i<iHeightGrid;i++)
{
for(int j=0;j<iWidthGrid;j++)
{
if(aryDiamonds[i][j]==1)
{
rtnRowColNos[i][0]=referPoint[0]+i;
rtnRowColNos[i][1]=referPoint[1]+j;
break;
}
}
}
/*只适合方块5的代码.
if(iSortNo==5)
{
rtnRowColNos[0][0]=referPoint[0];
rtnRowColNos[0][1]=referPoint[1];
rtnRowColNos[1][0]=referPoint[0];
rtnRowColNos[1][1]=referPoint[1]+1;
}*/
return rtnRowColNos;
}
//返回判定向右移动时判定接触的方块部分的坐标
public int[][] rightTouchGrids()
{
int[][] rtnRowColNos=new int[iHeightGrid][2];
for(int i=0;i<iHeightGrid;i++)
{
for(int j=iWidthGrid-1;j>=0;j--)
{
if(aryDiamonds[i][j]==1)
{
rtnRowColNos[i][0]=referPoint[0]+i;
rtnRowColNos[i][1]=referPoint[1]+j;
break;
}
}
}
return rtnRowColNos;
}
//返回判定向下移动时判定接触的方块部分的坐标
public int[][] downTouchGrids()
{
int[][] rtnRowColNos=new int[iWidthGrid][2];
for(int i=0;i<iWidthGrid;i++)
{
for(int j=0;j<iHeightGrid;j++)
{
if(aryDiamonds[j][i]==1)
{
rtnRowColNos[i][0]=referPoint[0]+j;
rtnRowColNos[i][1]=referPoint[1]+i;
break;
}
}
}
return rtnRowColNos;
}
public void initDiamondsTable()
{
diamondsTable=new int[SORTNUM][];
diamondsTable[0]=new int[2];
diamondsTable[1]=new int[4];
diamondsTable[2]=new int[4];
diamondsTable[3]=new int[2];
diamondsTable[4]=new int[2];
diamondsTab
le[5]=new int[1];
diamondsTable[6]=new int[4];
//存放各种方块旋转后的下一个状态号.
for(int i=0;i<diamondsTable.length;i++)
for(int