<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
#table {float:left}
#table tr{height:20px;}
#table tr td{width:20px;}
#yl {float:left;margin-left:10px;}
#yl tr{height:20px;}
#yl tr td{width:20px;}
</style>
</head>
<body onkeydown="zhuan()" style="text-align: center">
<div style="width:350px;margin:0 auto;">
<table border="1" id="table" cellspacing="0">
</table>
<table border="1" id="yl" cellspacing="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table border="1" id="f" cellspacing="0" style="float:left;margin-left:10px;">
<tr>
<td> </td>
</tr>
</table>
</div>
<script type="text/javascript" charset="utf-8">
var fangkuai=new Array();
var a=new Array();
var map=new Array();
var tempmap=new Array();
var zhong;
var xzhong;
var xdx=4;
var xdy=0;
var fkg=0;
var fkk=0;
var fenshu=0;
var dingshiqi;
els();
function els()
{
init();
kuai();
zaofangkuai();
kuaitotemp();
xianshi();
xianshiyl();
dingSi();
}
//
function init()
{
var newtable=getId("table");
var ntbody=document.createElement ("tbody");
newtable.appendChild (ntbody);
for(var i=0;i<15;i++){
var row=document.createElement ("tr");
for(var j=0;j<10;j++){
var cell=document.createElement ("td");
cell.appendChild(document.createTextNode (" "));
row.appendChild (cell);
}
ntbody.appendChild (row);
}
for(h=0;h<newtable.rows.length;h++)
{
map[h]=new Array();
for(l=0;l<10;l++)
{
map[h][l]=0;
}
}
tempmap=newtempmap();
fen();
}
//
function zaofangkuai()
{
zhong=xzhong;
xzhong=Math.floor(Math.random()*a.length);
fangkuai=a[zhong];
xianshiyl();
getfkc(fangkuai);
}
//
function kuai()
{
a[0]=new Array([1,1,1,1],[0,0,0,0],[0,0,0,0],[0,0,0,0]);
a[1]=new Array([1,1,0,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]);
a[2]=new Array([1,1,1,0],[0,1,0,0],[0,0,0,0],[0,0,0,0]);
a[3]=new Array([0,1,1,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]);
a[4]=new Array([1,0,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]);
a[5]=new Array([0,0,1,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]);
zhong=Math.floor(Math.random()*a.length);
xzhong=Math.floor(Math.random()*a.length);
}
//
function zhuan()
{
document.documentElement.onkeydown = function(e){
e = e||window.event;var ec = e.which||e.keyCode;
switch(ec){
case 38:shang();break;
case 37:zuo();break;
case 39:you();break;
case 40:xia();break;
default:break
}
};
}
//
function shang()
{
tempkuai=new Array([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]);
tempkuai=fangkuai;
tempkuai=xuanzhuan(tempkuai);
tempkuai=dingwei(tempkuai);
getfkc(tempkuai);
if(chujie(tempkuai) && chongdie(xdx,xdy,tempkuai))
{
fangkuai=tempkuai;
}
getfkc(fangkuai);
kuaitotemp();
xianshi();
}
function zuo()
{
if(xdx-1>=0 && chongdie(xdx-1,xdy,fangkuai))
{xdx--;}
kuaitotemp();
xianshi();
}
function you()
{
if(xdx+fkk<10 && chongdie(xdx+1,xdy,fangkuai))
{xdx++;}
kuaitotemp();
xianshi();
}
function xia()
{
gaodu=getId("table");
if(xdy+fkg<gaodu.rows.length && chongdie(xdx,xdy+1,fangkuai))
{
xdy++;
}else{
luoshi();
xiaokuai();
xdy=0;
xdx=4;
zaofangkuai();
}
kuaitotemp();
xianshi();
}
//
function xuanzhuan(kuais)
{
tempkuai=new Array([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]);
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
tempkuai[h][l]=kuais[3-l][h];
}
}
return tempkuai;
}
//
function dingwei(kuai)
{
tempkuai=new Array([0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]);
minx=4;
miny=4;
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(kuai[h][l]==1)
{
if(h<miny)
{
miny=h;
}
if(l<minx)
{
minx=l;
}
}
}
}
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(kuai[h+miny][l+minx]=="")
{
tempkuai[h][l]=0;
}else
{
tempkuai[h][l]=kuai[h+miny][l+minx];
}
}
}
return tempkuai;
}
//
function kuaitotemp()
{
tempmap=newtempmap();
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(fangkuai[h][l]==1)
{
tempmap[h+xdy][l+xdx]=fangkuai[h][l];
}
}
}
}
//
function luoshi()
{
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(fangkuai[h][l]==1)
{
map[h+xdy][l+xdx]=fangkuai[h][l];
}
}
}
}
//
function chujie(s)
{
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(s[h][l]==1)
{
if(l+xdx>=10)
{return false;}
}
}
}
return true;
}
//
function chongdie(x,y,f)
{
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(f[h][l]==1 && map[h+y][l+x]==1)
return false;
}
}
return true;
}
//
function yidong()
{
gaodu=getId("table");
tempmap=newtempmap();
if(xdy+fkg<gaodu.rows.length && chongdie(xdx,xdy+1,fangkuai))
{
xdy++;
}else{
luoshi();
xiaokuai();
xdy=0;
xdx=4;
zaofangkuai();
}
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(fangkuai[h][l]==1)
tempmap[h+xdy][l+xdx]=fangkuai[h][l];
}
}
xianshi();
}
//
function xiaokuai()
{
gaodu=getId("table");
h=gaodu.rows.length-1;
while(h>=0)
{
zongshu=0;
for(l=0;l<10;l++)
{
if(map[h][l]==1)
{
zongshu++;
}
}
if(zongshu==10)
{
fenshu=fenshu+10;
fen()
for(xh=h;xh>=0;xh--)
{
if(xh==0)
{
for(l=0;l<10;l++)
{
map[xh][l]=0;
}
}else{
for(l=0;l<10;l++)
{
map[xh][l]=map[xh-1][l];
}
}
}
h=gaodu.rows.length-1;
}else{
h--;
}
}
}
// .
function getfkc(f)
{
fkg=0;
fkk=0;
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(f[h][l]==1)
{
if(h>=fkg)
{
fkg=h+1;
}
if(l>=fkk)
{
fkk=l+1;
}
}
}
}
}
//
function newtempmap()
{
newmap=new Array();
gaodu=getId("table");
for(h=0;h<gaodu.rows.length;h++)
{
newmap[h]=new Array()
for(l=0;l<10;l++)
{
newmap[h][l]=0;
}
}
return newmap;
}
//
function xianshiyl()
{
gaodu=getId("yl");
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(a[xzhong][h][l]==1)
{
gaodu.rows[h].cells[l].style.background="#FF0000";
}else
{
gaodu.rows[h].cells[l].style.background="#FFFFFF";
}
}
}
}
//
function xianshi()
{
gaodu=getId("table");
for(h=0;h<gaodu.rows.length;h++)
{
for(l=0;l<10;l++)
{
if(map[h][l]==1 || tempmap[h][l]==1)
{
gaodu.rows[h].cells[l].style.background="#FF0000";
}else
{
gaodu.rows[h].cells[l].style.background="#FFFFFF";
}
}
}
}
//
function shibai()
{
for(h=0;h<4;h++)
{
for(l=0;l<4;l++)
{
if(fangkuai[h][l]==1 && map[h+xdy][l+xdx]==1)
return true;
}
}
return false;
}
//
function fen()
{
s=getId("f");
s.rows[0].cells[0].innerHTML=" :"+fenshu;
}
function getId(a)
{
return document.getElementById(a);
}
function dingSi()
{
dingshiqi=setInterval("yidong()",700);
}
</script>
</body>
</html>