java课程设计-贪吃蛇代码(3)

发布时间:2021-06-06

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

java课程设计-贪吃蛇代码(3).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219