intblockInitCol;//新出现块的起始列坐标
int[][]scrArr;//屏幕数组
Blockb;//对方快的引用
//画布类的构造方法
GameCanvas(){
rowNum=15;
columnNum=10;
maxAllowRowNum=rowNum-2;
b=newBlock(this);
blockInitRow=rowNum-1;
blockInitCol=columnNum/2-2;
scrArr=newint[32][32];
}
//初始化屏幕,并将屏幕数组清零的方法
voidinitScr(){
for(inti=0;i
for(intj=0;j scrArr[j]=0;
b.reset();
repaint();
}
//重新刷新画布方法
publicvoidpaint(Graphicsg){
for(inti=0;i for(intj=0;j drawUnit(i,j,scrArr[j]);
}
//画方块的方法
publicvoiddrawUnit(introw,intcol,inttype){
scrArr[row][col]=type;
Graphicsg=getGraphics();
tch(type){//表示画方快的方法
case0:g.setColor(Color.black);break;//以背景为颜色画
case1:g.setColor(Color.blue);break;//画正在下落的方块
case2:g.setColor(Color.magenta);break;//画已经落下的方法
}
g.fill3DRect(col*unitSize,getSize().height-(row+1)*unitSize,unitSize,unitSize,true);
g.dispose();
}
publicBlockgetBlock(){
returnb;//返回block实例的引用
}
//返回屏幕数组中(row,col)位置的属性值
publicintgetScrArrXY(introw,intcol){
if(row<0||row>=rowNum||col<0||col>=columnNum)
return(-1);
else
return(scrArr[row][col]);
}
//返回新块的初始行坐标方法
publicintgetInitRow(){
return(blockInitRow);//返回新块的初始行坐标
}
//返回新块的初始列坐标方法
publicintgetInitCol(){
return(blockInitCol);//返回新块的初始列坐标
}
//满行删除方法
voiddeleteFullLine(){
intfull_line_num=0;
intk=0;
for(inti=0;i booleanisfull=true;
L1:for(intj=0;j