1 Star 0 Fork 2

QCCS/game-html5-snake

forked from 老雷/game-html5-snake 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
1k2.js 1023 Bytes
一键复制 编辑 原始数据 按行查看 历史
Zongmin Lei 提交于 2013-12-05 18:05 . 1k 完成,最终结果1023字节
eval('I="fillStyle",J="fillRect",K="#e96900",c=document.getElementById("c"),C=c.getContext("2d"),w=h=20,W=c.width,H=c.height,M=W/w,N=H/h,V=parseInt,R=Math.random,T=setTimeout,D={97:{x:-1,y:0},115:{x:0,y:1},100:{x:1,y:0},119:{x:0,y:-1}},B=[{x:V(w/2),y:h,d:119}],f=X();onkeypress=@(e){if(D[e.which]){B[0].d=e.which}};C.m=@(f,a){% C[f].apply(C,a),C};C.s=@(f,v){% C[f]=v,C};@ P(p,a,b,c){C.s("strokeStyle","#fff").m("strokeRect",[p.x*M,p.y*N,M,N]).s(I,c||"#aaa").m(J,[p.x*M,p.y*N,M,N])}@ X(){var p={x:V(R()*w),y:V(R()*h)};% B.some(s)?X():p}@ o(){C.s(I,K).s("font","bold 24px 宋体").m("fillText",["游戏结束",(W-24*4)/2,(H-24)/2])}@ n(p){var d=D[p.d];%{x:p.x+d.x,y:p.y+d.y,d:p.d}}@ s(a,b){% a.x==b.x&&a.y==b.y}@ g(){var a=n(B[0]),L=B.length,i=0;if(!(a.x>=0&&a.x<w&&a.y>=0&&a.y<h)){% o()}while(i<L){if(s(a,B[i++])){% o()}}B.unshift(a);(f.x==a.x&&f.y==a.y)?f=X():B.pop();C.s(I,"#f1fedd").m(J,[0,0,W,H]);P(f,0,0,K);P(B[0],0,0,"#2d64b3");B.slice(1).forEach(P);T(g,200-L*1.5)}g()'.replace(/@/g,'function').replace(/%/g,'return'))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/qianchaochushui/game-html5-snake.git
git@gitee.com:qianchaochushui/game-html5-snake.git
qianchaochushui
game-html5-snake
game-html5-snake
master

搜索帮助