&& (head.y + Node.H) == food.y)
return true;
else
return false;
}
// ----------是否碰撞
private boolean isCollsion() {
Node node = body.get(0);
// ------------碰壁
if (derection == Snake.RIGHT && node.x == 280)
return true;
if (derection == Snake.UP && node.y == 0)
return true;
if (derection == Snake.LEFT && node.x == 0)
return true;
if (derection == Snake.DOWN && node.y == 380)
return true;
// --------------蛇头碰到蛇身
Node temp = null;
int i = 0;
for (i = 3; i < body.size(); i++) {
temp = body.get(i);
if (temp.x == node.x && temp.y == node.y)
break;
}
if (i < body.size())
return true;
else
return false;
}
// -------在随机的地方产生食物
public void makeFood() {
Node node = new Node(0, 0);
boolean isInBody = true;
int x = 0, y = 0;
int X = 0, Y = 0;
int i = 0;
while (isInBody) {
x = (int) (Math.random() * 15);
y = (int) (Math.random() * 20);
X = x * Node.W;
Y = y * Node.H;