HTML编写地贪吃蛇代码.docx
- 文档编号:5238953
- 上传时间:2022-12-14
- 格式:DOCX
- 页数:20
- 大小:16.29KB
HTML编写地贪吃蛇代码.docx
《HTML编写地贪吃蛇代码.docx》由会员分享,可在线阅读,更多相关《HTML编写地贪吃蛇代码.docx(20页珍藏版)》请在冰豆网上搜索。
HTML编写地贪吃蛇代码
varfangxiang;
fangxiang=4;
varsk=newArray(18);
sk[0]="5,5";
sk[1]="5,4";
sk[2]="5,3";
varlong=3;
varzhanshichunweiba;
varshiwu="15,15";
varshudu=250;
varmovedong=true;
varshifouchongzhi=true;
functionkeydown(){
if(event.keyCode==38){
if(fangxiang!
=2)fangxiang=1;
if(fangxiang==2)fangxiang=2;
}
if(event.keyCode==40){
if(fangxiang!
=1)fangxiang=2;
if(fangxiang==1)fangxiang=1;
}
if(event.keyCode==37){
if(fangxiang!
=4)fangxiang=3;
if(fangxiang==4)fangxiang=4;
}
if(event.keyCode==39){
if(fangxiang!
=3)fangxiang=4;
if(fangxiang==3)fangxiang=3;
}
}
functionkaishi(){
if(shifouchongzhi){
shifouchongzhi=false;
document.getElementById(sk[0]).style.backgroundColor="red";
document.getElementById(sk[1]).style.backgroundColor="red";
document.getElementById(sk[2]).style.backgroundColor="red";
document.getElementById(shiwu).style.backgroundColor="blue";
move();
}
else
alert("你要先重置");
}
functionchongzhi(){
shifouchongzhi=true;
shiwu="15,15";
shudu=250;
fangxiang=4;
sk[0]="5,5";
sk[1]="5,4";
sk[2]="5,3";
long=3;
varm=document.getElementsByTagName("td");
for(varn=0;n<400;n++){
m[n].style.backgroundColor="yellow";
}
movedong=true;
}
functiondong(){
zhanshichunweiba=sk[long-1];
for(varm=long-1;m>0;m--){
sk[m]=sk[m-1]
}
vari=sk[0].split(',');
if(fangxiang==1){i[0]--;sk[0]=i[0]+','+i[1]}
if(fangxiang==2){i[0]++;sk[0]=i[0]+','+i[1]}
if(fangxiang==3){i[1]--;sk[0]=i[0]+','+i[1]}
if(fangxiang==4){i[1]++;sk[0]=i[0]+','+i[1]}
}
functionzhenchanshengshiwu(){
varx;
vary;
x=Math.round(Math.random()*19);
y=Math.round(Math.random()*19);
shiwu=x+','+y;
chanshengshiwu();
}
functionchanshengshiwu(){
for(varm=0;m if(shiwu==sk[m]){ zhenchanshengshiwu(); } document.getElementById(shiwu).style.backgroundColor="blue"; } functionchishiwu(){ if(shiwu==sk[0]){ long++; sk[long-1]=zhanshichunweiba; document.getElementById(sk[long-1]).style.backgroundColor="red"; chanshengshiwu(); } } functionjieshujiashu(){ vari=sk[0].split(','); if(i[0]<0||i[0]>19||i[1]<0||i[1]>19){ alert("你死求"); movedong=false; } if(long>=6){ shudu=200; } if(long>=9){ shudu=150; } if(long>=12){ shudu=100; } if(long>=15){ shudu=80; } if(long>=18){ shudu=50; } if(long>=25){ alert("你真NB你赢了"); chongzhi(); movedong=false; } } functionmove(){ dong(); jieshujiashu(); for(varm=0;m document.getElementById(sk[m]).style.backgroundColor="red"; } document.getElementById(zhanshichunweiba).style.backgroundColor="yellow"; chishiwu(); if(movedong) setTimeout("move()",shudu); }
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。 copyright@ 2008-2022 冰点文档网站版权所有 经营许可证编号:鄂ICP备2022015515号-1
冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。