HTML编写地贪吃蛇代码.doc
<html><head><title>使用表格</title></head><script language="JavaScript">var fangxiang;fangxiang=4;var sk=new Array(18);sk0="5,5"sk1="5,4"sk2="5,3"var long=3;var zhanshichunweiba;var shiwu="15,15"var shudu=250;var movedong=true;var shifouchongzhi=true;function keydown()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;function kaishi()if(shifouchongzhi)shifouchongzhi=false;document.getElementById(sk0).style.backgroundColor = "red"document.getElementById(sk1).style.backgroundColor = "red"document.getElementById(sk2).style.backgroundColor = "red"document.getElementById(shiwu).style.backgroundColor = "blue"move();elsealert("你要先重置");function chongzhi()shifouchongzhi=true;shiwu="15,15"shudu=250;fangxiang=4;sk0="5,5"sk1="5,4"sk2="5,3"long=3;var m=document.getElementsByTagName("td");for(var n=0;n<400;n+)mn.style.backgroundColor = "yellow"movedong=true;function dong()zhanshichunweiba=sklong-1;for(var m=long-1;m>0;m-)skm=skm-1var i=sk0.split(',');if(fangxiang=1)i0-;sk0=i0+','+i1if(fangxiang=2)i0+;sk0=i0+','+i1if(fangxiang=3)i1-;sk0=i0+','+i1if(fangxiang=4)i1+;sk0=i0+','+i1function zhenchanshengshiwu()var x;var y;x=Math.round(Math.random()*19);y=Math.round(Math.random()*19);shiwu=x+','+y;chanshengshiwu();function chanshengshiwu()for(var m=0;m<long;m+)if(shiwu=skm)zhenchanshengshiwu();document.getElementById(shiwu).style.backgroundColor = "blue"function chishiwu()if(shiwu=sk0)long+;sklong-1=zhanshichunweiba;document.getElementById(sklong-1).style.backgroundColor = "red"chanshengshiwu();function jieshujiashu()var i=sk0.split(',');if(i0<0|i0>19|i1<0|i1>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;function move()dong();jieshujiashu();for(var m=0;m<long;m+)document.getElementById(skm).style.backgroundColor = "red"document.getElementById(zhanshichunweiba).style.backgroundColor = "yellow"chishiwu();if(movedong)setTimeout("move()",shudu);</script><body onkeydown="keydown()"> <input type="button" width="80" value="开始" onclick="kaishi();"> <input type="button" width="80" value="重置" onclick="chongzhi()"><table border ="0" cellspacing="0" id="quanbu"> <tr> <td id="0,0" bgcolor="yellow" width="20" height="20"> </td> <td id="0,1" bgcolor="yellow" width="20" height="20"> </td> <td id="0,2" bgcolor="yellow" width="20" height="20"> </td> <td id="0,3" bgcolor="yellow" width="20" height="20"> </td> <td id="0,4" bgcolor="yellow" width="20" height="20"> </td> <td id="0,5" bgcolor="yellow" width="20" height="20"> </td> <td id="0,6" bgcolor="yellow" width="20" height="20"> </td> <td id="0,7" bgcolor="yellow" width="20" height="20"> </td> <td id="0,8" bgcolor="yellow" width="20" height="20"> </td> <td id="0,9" bgcolor="yellow" width="20" height="20"> </td> <td id="0,10" bgcolor="yellow" width="20" height="20"> </td> <td id="0,11" bgcolor="yellow" width="20" height="20"> </td> <td id="0,12" bgcolor="yellow" width="20" height="20"> </td> <td id="0,13" bgcolor="yellow" width="20" height="20"> </td> <td id="0,14" bgcolor="yellow" width="20" height="20"> </td> <td id="0,15" bgcolor="yellow" width="20" height="20"> </td> <td id="0,16" bgcolor="yellow" width="20" height="20"> </td> <td id="0,17" bgcolor="yellow" width="20" height="20"> </td> <td id="0,18" bgcolor="yellow" width="20" height="20"> </td> <td id="0,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="1,0" bgcolor="yellow" width="20" height="20"> </td> <td id="1,1" bgcolor="yellow" width="20" height="20"> </td> <td id="1,2" bgcolor="yellow" width="20" height="20"> </td> <td id="1,3" bgcolor="yellow" width="20" height="20"> </td> <td id="1,4" bgcolor="yellow" width="20" height="20"> </td> <td id="1,5" bgcolor="yellow" width="20" height="20"> </td> <td id="1,6" bgcolor="yellow" width="20" height="20"> </td> <td id="1,7" bgcolor="yellow" width="20" height="20"> </td> <td id="1,8" bgcolor="yellow" width="20" height="20"> </td> <td id="1,9" bgcolor="yellow" width="20" height="20"> </td> <td id="1,10" bgcolor="yellow" width="20" height="20"> </td> <td id="1,11" bgcolor="yellow" width="20" height="20"> </td> <td id="1,12" bgcolor="yellow" width="20" height="20"> </td> <td id="1,13" bgcolor="yellow" width="20" height="20"> </td> <td id="1,14" bgcolor="yellow" width="20" height="20"> </td> <td id="1,15" bgcolor="yellow" width="20" height="20"> </td> <td id="1,16" bgcolor="yellow" width="20" height="20"> </td> <td id="1,17" bgcolor="yellow" width="20" height="20"> </td> <td id="1,18" bgcolor="yellow" width="20" height="20"> </td> <td id="1,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="2,0" bgcolor="yellow" width="20" height="20"> </td> <td id="2,1" bgcolor="yellow" width="20" height="20"> </td> <td id="2,2" bgcolor="yellow" width="20" height="20"> </td> <td id="2,3" bgcolor="yellow" width="20" height="20"> </td> <td id="2,4" bgcolor="yellow" width="20" height="20"> </td> <td id="2,5" bgcolor="yellow" width="20" height="20"> </td> <td id="2,6" bgcolor="yellow" width="20" height="20"> </td> <td id="2,7" bgcolor="yellow" width="20" height="20"> </td> <td id="2,8" bgcolor="yellow" width="20" height="20"> </td> <td id="2,9" bgcolor="yellow" width="20" height="20"> </td> <td id="2,10" bgcolor="yellow" width="20" height="20"> </td> <td id="2,11" bgcolor="yellow" width="20" height="20"> </td> <td id="2,12" bgcolor="yellow" width="20" height="20"> </td> <td id="2,13" bgcolor="yellow" width="20" height="20"> </td> <td id="2,14" bgcolor="yellow" width="20" height="20"> </td> <td id="2,15" bgcolor="yellow" width="20" height="20"> </td> <td id="2,16" bgcolor="yellow" width="20" height="20"> </td> <td id="2,17" bgcolor="yellow" width="20" height="20"> </td> <td id="2,18" bgcolor="yellow" width="20" height="20"> </td> <td id="2,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="3,0" bgcolor="yellow" width="20" height="20"> </td> <td id="3,1" bgcolor="yellow" width="20" height="20"> </td> <td id="3,2" bgcolor="yellow" width="20" height="20"> </td> <td id="3,3" bgcolor="yellow" width="20" height="20"> </td> <td id="3,4" bgcolor="yellow" width="20" height="20"> </td> <td id="3,5" bgcolor="yellow" width="20" height="20"> </td> <td id="3,6" bgcolor="yellow" width="20" height="20"> </td> <td id="3,7" bgcolor="yellow" width="20" height="20"> </td> <td id="3,8" bgcolor="yellow" width="20" height="20"> </td> <td id="3,9" bgcolor="yellow" width="20" height="20"> </td> <td id="3,10" bgcolor="yellow" width="20" height="20"> </td> <td id="3,11" bgcolor="yellow" width="20" height="20"> </td> <td id="3,12" bgcolor="yellow" width="20" height="20"> </td> <td id="3,13" bgcolor="yellow" width="20" height="20"> </td> <td id="3,14" bgcolor="yellow" width="20" height="20"> </td> <td id="3,15" bgcolor="yellow" width="20" height="20"> </td> <td id="3,16" bgcolor="yellow" width="20" height="20"> </td> <td id="3,17" bgcolor="yellow" width="20" height="20"> </td> <td id="3,18" bgcolor="yellow" width="20" height="20"> </td> <td id="3,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="4,0" bgcolor="yellow" width="20" height="20"> </td> <td id="4,1" bgcolor="yellow" width="20" height="20"> </td> <td id="4,2" bgcolor="yellow" width="20" height="20"> </td> <td id="4,3" bgcolor="yellow" width="20" height="20"> </td> <td id="4,4" bgcolor="yellow" width="20" height="20"> </td> <td id="4,5" bgcolor="yellow" width="20" height="20"> </td> <td id="4,6" bgcolor="yellow" width="20" height="20"> </td> <td id="4,7" bgcolor="yellow" width="20" height="20"> </td> <td id="4,8" bgcolor="yellow" width="20" height="20"> </td> <td id="4,9" bgcolor="yellow" width="20" height="20"> </td> <td id="4,10" bgcolor="yellow" width="20" height="20"> </td> <td id="4,11" bgcolor="yellow" width="20" height="20"> </td> <td id="4,12" bgcolor="yellow" width="20" height="20"> </td> <td id="4,13" bgcolor="yellow" width="20" height="20"> </td> <td id="4,14" bgcolor="yellow" width="20" height="20"> </td> <td id="4,15" bgcolor="yellow" width="20" height="20"> </td> <td id="4,16" bgcolor="yellow" width="20" height="20"> </td> <td id="4,17" bgcolor="yellow" width="20" height="20"> </td> <td id="4,18" bgcolor="yellow" width="20" height="20"> </td> <td id="4,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="5,0" bgcolor="yellow" width="20" height="20"> </td> <td id="5,1" bgcolor="yellow" width="20" height="20"> </td> <td id="5,2" bgcolor="yellow" width="20" height="20"> </td> <td id="5,3" bgcolor="yellow" width="20" height="20"> </td> <td id="5,4" bgcolor="yellow" width="20" height="20"> </td> <td id="5,5" bgcolor="yellow" width="20" height="20"> </td> <td id="5,6" bgcolor="yellow" width="20" height="20"> </td> <td id="5,7" bgcolor="yellow" width="20" height="20"> </td> <td id="5,8" bgcolor="yellow" width="20" height="20"> </td> <td id="5,9" bgcolor="yellow" width="20" height="20"> </td> <td id="5,10" bgcolor="yellow" width="20" height="20"> </td> <td id="5,11" bgcolor="yellow" width="20" height="20"> </td> <td id="5,12" bgcolor="yellow" width="20" height="20"> </td> <td id="5,13" bgcolor="yellow" width="20" height="20"> </td> <td id="5,14" bgcolor="yellow" width="20" height="20"> </td> <td id="5,15" bgcolor="yellow" width="20" height="20"> </td> <td id="5,16" bgcolor="yellow" width="20" height="20"> </td> <td id="5,17" bgcolor="yellow" width="20" height="20"> </td> <td id="5,18" bgcolor="yellow" width="20" height="20"> </td> <td id="5,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="6,0" bgcolor="yellow" width="20" height="20"> </td> <td id="6,1" bgcolor="yellow" width="20" height="20"> </td> <td id="6,2" bgcolor="yellow" width="20" height="20"> </td> <td id="6,3" bgcolor="yellow" width="20" height="20"> </td> <td id="6,4" bgcolor="yellow" width="20" height="20"> </td> <td id="6,5" bgcolor="yellow" width="20" height="20"> </td> <td id="6,6" bgcolor="yellow" width="20" height="20"> </td> <td id="6,7" bgcolor="yellow" width="20" height="20"> </td> <td id="6,8" bgcolor="yellow" width="20" height="20"> </td> <td id="6,9" bgcolor="yellow" width="20" height="20"> </td> <td id="6,10" bgcolor="yellow" width="20" height="20"> </td> <td id="6,11" bgcolor="yellow" width="20" height="20"> </td> <td id="6,12" bgcolor="yellow" width="20" height="20"> </td> <td id="6,13" bgcolor="yellow" width="20" height="20"> </td> <td id="6,14" bgcolor="yellow" width="20" height="20"> </td> <td id="6,15" bgcolor="yellow" width="20" height="20"> </td> <td id="6,16" bgcolor="yellow" width="20" height="20"> </td> <td id="6,17" bgcolor="yellow" width="20" height="20"> </td> <td id="6,18" bgcolor="yellow" width="20" height="20"> </td> <td id="6,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="7,0" bgcolor="yellow" width="20" height="20"> </td> <td id="7,1" bgcolor="yellow" width="20" height="20"> </td> <td id="7,2" bgcolor="yellow" width="20" height="20"> </td> <td id="7,3" bgcolor="yellow" width="20" height="20"> </td> <td id="7,4" bgcolor="yellow" width="20" height="20"> </td> <td id="7,5" bgcolor="yellow" width="20" height="20"> </td> <td id="7,6" bgcolor="yellow" width="20" height="20"> </td> <td id="7,7" bgcolor="yellow" width="20" height="20"> </td> <td id="7,8" bgcolor="yellow" width="20" height="20"> </td> <td id="7,9" bgcolor="yellow" width="20" height="20"> </td> <td id="7,10" bgcolor="yellow" width="20" height="20"> </td> <td id="7,11" bgcolor="yellow" width="20" height="20"> </td> <td id="7,12" bgcolor="yellow" width="20" height="20"> </td> <td id="7,13" bgcolor="yellow" width="20" height="20"> </td> <td id="7,14" bgcolor="yellow" width="20" height="20"> </td> <td id="7,15" bgcolor="yellow" width="20" height="20"> </td> <td id="7,16" bgcolor="yellow" width="20" height="20"> </td> <td id="7,17" bgcolor="yellow" width="20" height="20"> </td> <td id="7,18" bgcolor="yellow" width="20" height="20"> </td> <td id="7,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="8,0" bgcolor="yellow" width="20" height="20"> </td> <td id="8,1" bgcolor="yellow" width="20" height="20"> </td> <td id="8,2" bgcolor="yellow" width="20" height="20"> </td> <td id="8,3" bgcolor="yellow" width="20" height="20"> </td> <td id="8,4" bgcolor="yellow" width="20" height="20"> </td> <td id="8,5" bgcolor="yellow" width="20" height="20"> </td> <td id="8,6" bgcolor="yellow" width="20" height="20"> </td> <td id="8,7" bgcolor="yellow" width="20" height="20"> </td> <td id="8,8" bgcolor="yellow" width="20" height="20"> </td> <td id="8,9" bgcolor="yellow" width="20" height="20"> </td> <td id="8,10" bgcolor="yellow" width="20" height="20"> </td> <td id="8,11" bgcolor="yellow" width="20" height="20"> </td> <td id="8,12" bgcolor="yellow" width="20" height="20"> </td> <td id="8,13" bgcolor="yellow" width="20" height="20"> </td> <td id="8,14" bgcolor="yellow" width="20" height="20"> </td> <td id="8,15" bgcolor="yellow" width="20" height="20"> </td> <td id="8,16" bgcolor="yellow" width="20" height="20"> </td> <td id="8,17" bgcolor="yellow" width="20" height="20"> </td> <td id="8,18" bgcolor="yellow" width="20" height="20"> </td> <td id="8,19" bgcolor="yellow" width="20" height="20"> </td> </tr> <tr> <td id="9,0" bgcolor="yellow" width="20" height="20"> </td> <td id="9,1" bgcolor="yellow" width="20" height="20"> </td> <td id="9,2" bgcolor="yellow" width="20" height="20"> </td> <td id="9,3" bgcolor="yellow" width="20" height="20"> </td> <td id="9,4" bgcolor="yellow" width="20" height=