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日
Java开发工程师_初心 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日
最近浏览更多
罗清晨 LV11
2月21日
微信网友_6790966844739584 LV2
2023年12月28日
ClydeSon LV5
2023年12月27日
lshlsh
2023年12月25日
暂无贡献等级
bangyiyang LV2
2023年12月21日
b5438b LV7
2023年12月20日
fenghuijun LV26
2023年12月10日
hhqazmlp LV1
2023年10月30日
19050126312 LV1
2023年10月30日
jiemomo LV12
2023年10月19日