public void move(){
for(int i=this.length-1;i>0;i--){
x[i]=x[i-1];
y[i]=y[i-1];
}
if(direction==1){
x[0]+=10;
}else if(direction==2){
x[0]-=10;
}else if(direction==3){
y[0]+=10;
}else{
y[0]-=10;
}
}
//检查小蛇是否撞墙或撞自己
public void check(){
//检查是否撞墙
if(this.x[0]<50||this.x[0]>440||this.y[0]<50||this.y[0]>340){
this.isLive=false;
}
//检查是否撞自己
for(int i=1;i
if(this.x[0]==this.x[i]&;&;this.y[0]==this.y[i]){
this.isLive=false;
}
}
}
//是否吃掉了食物
public boolean eat(int x,int y){
if(this.x[0]==x&;&;this.y[0]==y){
this.length++;
return true;
}else{
return false;
}
}
}