java课程设计-贪吃蛇代码(6)
发布时间:2021-06-06
发布时间:2021-06-06
Y += Node.H;
break;
}
body.add(0, new Node(X, Y));
// ---------------去掉蛇尾
body.remove(body.size() - 1);
}
}
}
// ---------组成蛇身的单位,食物
class Node {
public static final int W = 20;
public static final int H = 20;
int x;
int y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
}
// ------画板
class SnakePanel extends JPanel {
Snake snake;
public SnakePanel(Snake snake) {
this.snake = snake;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Node node = null;
for (int i = 0; i < snake.body.size(); i++) {// ---黄绿间隔画蛇身 if (i % 2 == 0)
g.setColor(Color.green);
else
g.setColor(Color.yellow);
node = snake.body.get(i);
g.fillRect(node.x, node.y, node.H,
*******************试用*********************
}
node = snake.food; node.W);//
上一篇:硬笔书法 第一课时
下一篇:《聪明人和傻子和奴才》教学设计