HTML编写地贪吃蛇代码.docx

上传人:b****4 文档编号:5238953 上传时间:2022-12-14 格式:DOCX 页数:20 大小:16.29KB
下载 相关 举报
HTML编写地贪吃蛇代码.docx_第1页
第1页 / 共20页
HTML编写地贪吃蛇代码.docx_第2页
第2页 / 共20页
HTML编写地贪吃蛇代码.docx_第3页
第3页 / 共20页
HTML编写地贪吃蛇代码.docx_第4页
第4页 / 共20页
HTML编写地贪吃蛇代码.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

HTML编写地贪吃蛇代码.docx

《HTML编写地贪吃蛇代码.docx》由会员分享,可在线阅读,更多相关《HTML编写地贪吃蛇代码.docx(20页珍藏版)》请在冰豆网上搜索。

HTML编写地贪吃蛇代码.docx

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);

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1