egg.java
来自「尚学堂的java的贪吃蛇,希望能对大家有所帮助」· Java 代码 · 共 62 行
JAVA
62 行
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;
/**
* 代表蛋
* @author Administrator
*
*/
public class Egg {
int row, col;
int w = Yard.BLOCK_SIZE;
int h = Yard.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(r.nextInt(Yard.ROWS-2) + 2, r.nextInt(Yard.COLS));
}
public void reAppear() {
this.row = r.nextInt(Yard.ROWS-2) + 2;
this.col = r.nextInt(Yard.COLS);
}
public Rectangle getRect() {
return new Rectangle(Yard.BLOCK_SIZE * col, Yard.BLOCK_SIZE * row, w, h);
}
public void draw(Graphics g) {
Color c = g.getColor();
g.setColor(color);
g.fillOval(Yard.BLOCK_SIZE * col, Yard.BLOCK_SIZE * row, w, h);
g.setColor(c);
if(color == Color.GREEN) color = Color.RED;
else color = Color.GREEN;
}
public int getCol() {
return col;
}
public void setCol(int col) {
this.col = col;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?