defaultsnakeunit.java~17~
来自「前段时间帮同学写了个简单动画程序:“贪食蛇的原型”」· JAVA~17~ 代码 · 共 36 行
JAVA~17~
36 行
package com.cxlife.snake;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Component;
public class DefaultSnakeUnit extends SnakeUnit{
public DefaultSnakeUnit(final Component pComponent){
this.canvas = pComponent;
}
//绘制蛇身
public Graphics doDraw(final Component pComponent){
if (pComponent == null)
return null;
Graphics g = pComponent.getGraphics();
g.setColor(super.snake_color);//设置蛇身的颜色.
g.fillRect(super.left,super.top,super.width,super.height);
g.dispose();
return pComponent.getGraphics();
}
//对象克窿
public Object clone(){
DefaultSnakeUnit dsu = new DefaultSnakeUnit(null);
dsu.canvas = this.canvas;
dsu.left = this.left;
dsu.top = this.top;
dsu.width= this.width;
dsu.height = this.height;
dsu.curr_direction = this.curr_direction;
dsu.next_direction = this.next_direction;
dsu.snake_color = this.snake_color;
return dsu;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?