switch (dir) { // 不同的方向判断的方法也不一样
case Worm.LEFT:
return ((y == this.y) && ((x <= this.x) && (x >= getEndX())));
case Worm.RIGHT:
return ((y == this.y) && ((x >= this.x) && (x <= getEndX())));
case Worm.UP:
return ((x == this.x) && ((y <= this.y) && (y >= getEndY())));
case Worm.DOWN:
return ((x == this.x) && ((y >= this.y) && (y <= getEndY())));
} |