<div class="codetitle"> <span><a style="CURSOR: pointer" data="13555" class="copybut" id="copybut13555" onclick="doCopy('code13555')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code13555"> <br><style type="text/css"><BR>body { background:#000; font:25px/25px 宋体;}<BR>#box { float:left;width:252px;border:#999 20px ridge;color:#9f9;text-shadow:2px 3px 1px #0f0; }<BR>#info { float:left;color:#cfc;padding:24px; }<BR>#next { padding:8px;width:105px;color:#9f9;text-shadow:2px 3px 1px #0f0; }<BR></style> <br><div id="box"></div> <div id="info">NEXT:<div id="next"></div> <div id="text"></div> </div> <br><script type="text/javascript"><BR>var map=eval("["+Array(23).join("0x801,")+"0xfff]");<BR>var tatris=[[0x6600],[0x2222,0xf00],[0xc600,0x2640],[0x6c00,0x4620],[0x4460,0x2e0,0x6220,0x740],[0x2260,0xe20,0x6440,0x4700],[0x2620,0x720,0x2320,0x2700]];<BR>var char={x:"\u3000",s:"\u25a0",t:"\u25a1"};<BR>var keycom={"38":"rotate(1)","40":"down()","37":"move(2,1)","39":"move(0.5,-1)","32":"0;pause=!pause"};<BR>var dia, pos, bak, run, next, pause=false, info={speed:1,lines:0,score:0};<BR>function start(){<BR> dia=next.d;<BR> bak=pos={fk:[],y:0,x:4,s:next.s};<BR> nextdia();<BR> document.getElementById("next").innerHTML=(next.d[next.s%next.d.length]|0x10000).toString(2).slice(-16).replace(/..../g,"$&<br/>").replace(/1/g,char.t).replace(/0/g,char.x);<BR> document.getElementById("text").innerHTML="SCORE:"+info.score+"<br/><br/>LINES:"+info.lines+"<br/><br/>SPEED:"+info.speed;<BR> rotate(0);<BR> run=setInterval("pause||down()",~~(Math.pow(1.3,12-info.speed)*30+20));<BR>}<BR>function over(){<BR> document.onkeydown=null;<BR> alert("GAME OVER");<BR>}<BR>function nextdia(){<BR> next={d:tatris[~~(Math.random()*7)],s:~~(Math.random()*4)};<BR>}<BR>function update(t){<BR> bak={fk:pos.fk.slice(0),y:pos.y,x:pos.x,s:pos.s};<BR> if(t) return;<BR> for(var i=0,a2=""; i<22; i++)<BR> a2+=map[i].toString(2).slice(1,-1)+"<br/>";<BR> for(var i=0,n; i<4; i++)<BR> if(/([^0]+)/.test(bak.fk[i].toString(2).replace(/1/g,char.t)))<BR> a2=a2.substr(0,n=(bak.y+i+1)*15-RegExp.$_.length-4)+RegExp.$1+a2.slice(n+RegExp.$1.length);<BR> document.getElementById("box").innerHTML=a2.replace(/1/g,char.s).replace(/0/g,char.x);<BR>}<BR>function is(){<BR> for(var i=0; i<4; i++)<BR> if((pos.fk[i]&map[pos.y+i])!=0) return pos=bak;<BR>}<BR>function rotate(r){<BR> var f=dia[pos.s=(pos.s+r)%dia.length];<BR> for(var i=0; i<4; i++)<BR> pos.fk[i]=(f>>(12-i*4)&15)<<pos.x;<BR> update(is());<BR>}<BR>function down(){<BR> ++pos.y;<BR> if(is()){<BR> for(var i=0, r=0; i<4 && pos.y+i<22; i++)<BR> if((map[pos.y+i]|=pos.fk[i])==0xfff){<BR> map.splice(pos.y+i,1), map.unshift(0x801);<BR> ++info.lines%20==0 && info.speed++, r++;<BR> }<BR> clearInterval(run);<BR> if(map[1]!=0x801) return over();<BR> info.score+=~~(Math.pow(r,1.5)*10)+2;<BR> start();<BR> }<BR> update();<BR>}<BR>function move(t,k){<BR> pos.x+=k;<BR> for(var i=0; i<4; i++)<BR> pos.fk[i]*=t;<BR> update(is());<BR>}<BR>document.onkeydown=function(e){<BR> eval("pause||"+keycom[(e?e:event).keyCode]);<BR>};<BR>nextdia();<BR>start();<BR></script><br> </div>