import java.awt.*;
import java.util.Random;
//贪吃蛇的蛋
public class Egg {
//蛋的位置行和列
int row=Config.ROWS;
int col=Config.COLS;
int width=Config.BLOCK_SIZE;
int height=Config.BLOCK_SIZE;
private static Random r=new Random();
private Color color =Color.green;
//构造器
public Egg(int row, int col){
this.row=row;
this.col=col;
}
public Egg(){
//this必须在第一行通过无参构造给有参构造赋值得到一种有参构造的效果
this(r.nextInt(Config.ROWS - 4) + 3,r.nextInt(Config.COLS-2)+1);
}
//当蛋被吃了蛋的位置改变
public void reAppear(){
this.row = r.nextInt(Config.ROWS-4) + 3;
this.col = r.nextInt(Config.COLS-2)+1;
}
//生成它的矩形的位置
public Rectangle getRect(){
return new Rectangle(Config.BLOCK_SIZE*col,Config.BLOCK_SIZE* row, width, height);
}
public void draw(Graphics g){
Color c = g.getColor();
g.setColor(color);
g.fillOval(Config.BLOCK_SIZE*col,Config.BLOCK_SIZE*row ,width ,height );
g.setColor(c);
if(color==Color.green) color=Color.red;
else color=Color.green;
}
}
最近下载更多
jiemomo LV12
2023年10月19日
baihaushu LV1
2023年6月13日
493240689 LV3
2023年5月11日
不正经的90后程序猿 LV1
2022年12月23日
微信网友_6258245891903488 LV7
2022年12月12日
neverthepoint LV1
2022年11月22日
小野猪ayu LV1
2022年10月25日
的还是看哈 LV3
2022年6月10日
bigtreemin LV6
2022年5月21日
小明pussabcd LV1
2022年5月16日
最近浏览更多
我真没招了 LV1
11月21日
鲁一宇 LV5
2024年12月24日
13133117021 LV5
2024年12月23日
MQ-EQW
2024年12月20日
暂无贡献等级
LeeLeo
2024年12月4日
暂无贡献等级
hoictas LV2
2024年11月26日
1220261962d
2024年10月15日
暂无贡献等级
三角阀 LV4
2024年7月13日
zr20050503 LV2
2024年6月27日
long123_356 LV8
2024年6月22日

