ArrayList<Node> body;// -----蛇体
Node food; // --------食物
int derection; // --------方向
int score;
int status;
int speed;
public static final int SLOW = 500;
public static final int MID = 300;
public static final int FAST = 100;
public static final int RUNNING = 1;
public static final int PAUSED = 2;
public static final int GAMEOVER = 3;
public static final int LEFT = 1;
public static final int UP = 2;
public static final int RIGHT = 3;
public static final int DOWN = 4;
public Snake() {
speed = Snake.SLOW;
score = 0;
isRun = false;
status = Snake.PAUSED; derection = Snake.RIGHT; body = new ArrayList<Node>(); body.add(new Node(60, 20));
body.add(new Node(40, 20));
body.add(new Node(20, 20));
makeFood();
}
// ------------判断食物是否被蛇吃掉
// -------如果食物在蛇运行方向的正前方,并且与蛇头接触,则被吃掉
private boolean isEaten() {
Node head = body.get(0);
if (derection == Snake.RIGHT && (head.x + Node.W) == food.x
&& head.y == food.y)
return true;
if (derection == Snake.LEFT && (head.x - Node.W) == food.x
&& head.y == food.y)
return true;
if (derection == Snake.UP && head.x == food.x
&& (head.y - Node.H) == food.y)
return true;
if (derection == Snake.DOWN && head.x == food.x