手机版

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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)