private void clearIfBitesSelf() { boolean clear = false; for (BodyPart part : bodyParts) { if (snakeX == part.getX() && snakeY == part.getY()) { clear = true; } } if (clear) { bodyParts.clear(); } }
private void registerAppleCollision(int previousX, int previousY) { changeAppleCoordinates(); BodyPart newBodyPart = new BodyPart(snakeBody); if (bodyParts.size() == 0) { newBodyPart.updatePosition(previousX, previousY); } else { BodyPart lastBodyPart = bodyParts.get(bodyParts.size() - 1); newBodyPart.updatePosition(lastBodyPart.getX(), lastBodyPart.getY()); } bodyParts.add(newBodyPart); System.out.printf("Now %d body parts", bodyParts.size()); }