史上最短小精悍的javascript编写的俄罗斯方块游戏,仅仅60行代码

阅读: 评论:0

史上最短小精悍的javascript编写的俄罗斯方块游戏,仅仅60行代码

史上最短小精悍的javascript编写的俄罗斯方块游戏,仅仅60行代码

原创整理不易,转载请注明出处:史上最短小精悍的javascript编写的俄罗斯方块游戏,仅仅60行代码

代码下载地址:.htm


直接上效果图:

通过左右下控制方向,上改变形状。

game over

<!doctype html><html><head></head><body><div id="box" style="width:252px;font:25px/25px 宋体;background:#000;color:#9f9;border:#999 20px ridge;text-shadow:2px 3px 1px #0f0;"></div><script>var domain="www.zuidaima";var author="zuidaima";var map=eval("["+Array(23).join("0x801,")+"0xfff]");var tatris=[[0x6600],[0x2222,0xf00],[0xc600,0x2640],[0x6c00,0x4620],[0x4460,0x2e0,0x6220,0x740],[0x2260,0xe20,0x6440,0x4700],[0x2620,0x720,0x2320,0x2700]];var keycom={"38":"rotate(1)","40":"down()","37":"move(2,1)","39":"move(0.5,-1)"};var dia, pos, bak, run;function start(){    dia=tatris[~~(Math.random()*7)];    bak=pos={fk:[],y:0,x:4,s:~~(Math.random()*4)};    rotate(0);}function over(){    document.οnkeydοwn=null;    clearInterval(run);    alert("GAME OVER");}function update(t){    bak={fk:pos.fk.slice(0),y:pos.y,x:pos.x,s:pos.s};    if(t) return;    for(var i=0,a2=""; i<22; i++)        a2+=map[i].toString(2).slice(1,-1)+"<br/>";    for(var i=0,n; i<4; i++)        if(/([^0]+)/.test(bak.fk[i].toString(2).replace(/1/g,"u25a1")))            a2=a2.substr(0,n=(bak.y+i+1)*15-RegExp.$_.length-4)+RegExp.$1+a2.slice(n+RegExp.$1.length);    ElementById("box").innerHTML&#place(/1/g,"u25a0").replace(/0/g,"u3000");}function is(){    for(var i=0; i<4; i++)        if((pos.fk[i]&map[pos.y+i])!=0) return pos=bak;}function rotate(r){    var f=dia[pos.s=(pos.s+r)%dia.length];    for(var i=0; i<4; i++)        pos.fk[i]=(f>>(12-i*4)&15)<<pos.x;    update(is());}function down(){    ++pos.y;    if(is()){        for(var i=0; i<4 && pos.y+i<22; i++)            if((map[pos.y+i]|=pos.fk[i])==0xfff)                map.splice(pos.y+i,1), map.unshift(0x801);        if(map[1]!=0x801) return over();        start();    }    update();}function move(t,k){    pos.x+=k;    for(var i=0; i<4; i++)        pos.fk[i]*=t;    update(is());}document.οnkeydοwn=function(e){    eval(keycom[(e?e:event).keyCode]);};start();run=setInterval("down()",400);</script></body></html>

 

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!

本文发布于:2024-02-02 03:44:07,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170681733441147.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23