'
Map=new Array()
for(y=0;y
'
Map[Fy][Fx]='F'
}
else CreatFood()
}
//创建蛇的位置
function CreateSnake(){
MainMap.innerHTML+=''
Map[Sy][Sx]='S'
}
//主移动--判断蛇头前面的是什么
function Move(){
Sx+=GoX
Sy+=GoY
if(Sy<0||Sy>=Rows)Move1()
else{
SnakeFront=Map[Sy][Sx]
if(SnakeFront=='0')Move2()
else{
if(SnakeFront=='F')Move3()
else Move1()
}
}
}
//重新开始
function Move1(){
ReStart=confirm("Game Over,重新开始?")
if(ReStart)window.location.reload()
}
var Times=200
//蛇前是空地时
function Move2(){
Map[AllDiv[0].y][AllDiv[0].x]='0'
AllDiv[0].removeNode(true)
CreateSnake()
setTimeout('Move()',Times)
}
//蛇前面是食物时
function Move3(){
CreateSnake()
AllSpan[0].removeNode(true)
CreatFood()
setTimeout('Move()',Times)
}
//蛇越行越快
function oTimes(){
Times-=5
if(Times>5)setTimeout('oTimes()',SpeedUp)
}
document.onkeydown=KeyDown
//方向
function KeyDown(){
Key=event.keyCode
switch(Key){
case 37:Dir(-1,0);break//左
case 39:Dir(1,0);break//右
case 38:Dir(0,-1);break//上
case 40:Dir(0,1);break}//下
return false
}
var Star=0
function Dir(x,y){
GoX=x
GoY=y
if(Star==0){
oTimes()
Star=1
Move()
}
}
//开始时运行
onload=CreateMap
</Script>