急求怎样用JavaScript写
<html><head><style>#boardtrtd{ :20px;}</style></head><script>vartbl;varstatus=0;vartimer;varscore=0;varboard=newArray(18);for(vari=0;i<18;i++){board[i]=newArray(10);}for(vari=0;i<18;i++){for(varj=0;j<10;j++){board[i][j]=0;}}varactiveBlock;functiongenera...全部
<html><head><style>#boardtrtd{ :20px;}</style></head><script>vartbl;varstatus=0;vartimer;varscore=0;varboard=newArray(18);for(vari=0;i<18;i++){board[i]=newArray(10);}for(vari=0;i<18;i++){for(varj=0;j<10;j++){board[i][j]=0;}}varactiveBlock;functiongenerateBlock(){activeBlock=null;activeBlock=newArray(4);vart=(Math。
floor(Math。random()*20)+1)%7;switch(t){case0:{activeBlock[0]={x:0,y:4};activeBlock[1]={x:1,y:4};activeBlock[2]={x:0,y:5};activeBlock[3]={x:1,y:5};break;}case1:{activeBlock[0]={x:0,y:3};activeBlock[1]={x:0,y:4};activeBlock[2]={x:0,y:5};activeBlock[3]={x:0,y:6};break;}case2:{activeBlock[0]={x:0,y:5};activeBlock[1]={x:1,y:4};activeBlock[2]={x:1,y:5};activeBlock[3]={x:2,y:4};break;}case3:{activeBlock[0]={x:0,y:4};activeBlock[1]={x:1,y:4};activeBlock[2]={x:1,y:5};activeBlock[3]={x:2,y:5};break;}case4:{activeBlock[0]={x:0,y:4};activeBlock[1]={x:1,y:4};activeBlock[2]={x:1,y:5};activeBlock[3]={x:1,y:6};break;}case5:{activeBlock[0]={x:0,y:4};activeBlock[1]={x:1,y:4};activeBlock[2]={x:2,y:4};activeBlock[3]={x:2,y:5};break;}case6:{activeBlock[0]={x:0,y:5};activeBlock[1]={x:1,y:4};activeBlock[2]={x:1,y:5};activeBlock[3]={x:1,y:6};break;}}for(vari=0;i<4;i++){if(isCellVali(activeBlock[i]。
x,activeBlock[i]。y)){returnfalse;}}returntrue;}functionmoveDown(){if(checkBottomBorder()){erase();for(vari=0;i<4;i++){activeBlock[i]。
x=activeBlock[i]。x+1;}paint();}else{clearInterval(timer);updateBoard();varlinesdeleteLine();if(lines!=0){scorescore=score+lines*10;eraseBoard();paintBoard();}if(!generateBlock()){alert("Gameover!");status=2;return;}paint();timer=setInterval(moveDown,1000)}}functionmoveLeft(){if(checkLeftBorder()){erase();for(vai=0;i<4;i++){activeBlock[i]。
y=activeBlock[i]。y-1;}paint();}}functionmoveRight(){if(checkRightBorder()){erase();forvai=0;i<4;i++){activeBlock[i]。
y=activeBlock[i]。y+1;}paint();}}functionrotate(){vartmpBlock=newArray(4);for(vari=0;i<4;++){tmpBlock[i]={x:0,y:0};}for(vari=0;i<4;i++答案补充){tmpBlock[i]。
x=activeBlock[i]。x;tmpBlock[i]。y=activeBlock[i]。y;}varc=Math。round((tmpBlock[0]。x+tmpBlock[1]。x+tmpBlock[2]。
x+tmpBlock[3]。x)/4);varcy=Math。round((tmpBlock[0]。y+tmpBlock[1]。y+tmpBlock[2]答案补充。y+tmpBlock[3]。
y)/4);for(vari=0;i<4;i++){tmpBlock[i]。x=cx+cy-activeBlock[i]。y;tmpBlock[i]。y=cy-cx+activeBlock[i]。
x;}for(vari=0;i<4;i++){if(!isCellValid(tmpBlock[i]。x,tmpBlock[i]。y)){return;}}erase();for(vari=0;i<4;i++){activeBlock[i]。
x=tmpBlock[i]。x;activeBlock[i]。y=tmpBlock[i]。y;}paint();}functioncheckLeftBorder(){for(vari=0;i<activeBlock。
length;i++){if(activeBlock[i]。y==0){returnfalse;}if(!isCellValid(activeBlock[i]。x,activeBlock[i]。
y-1)){returnfalse;}}returntrue;}functioncheckRightBor答案补充der(){for(vari=0;i<activeBlock。length;i++){if(activeBlock[i]。
y==9){returnfalse;}if(!isCellValid(activeBlock[i]。x,activeBlock[i]。y+1)){returnfalse;}}returntrue;}functioncheckBottomBorder(){for(vari=0;i<activeBlock。
length;i++){if(activeBlock[i]。x==17){returnfalse;}if(!isCellValid(activeBlock[i]。x+1,activeBlock[i]。
y)){returnfalse;}}returntrue;}functionisCellValid(x,y){if(x>17||x<0||y>9||y<0){returnfalse;}if(board[x][y]==1){returnfalse;}returntrue;}还有一部分发不了。
收起