📄 food.java
字号:
package greedSnake;
import java.util.Random;
import com.nttdocomo.ui.Graphics;
public class Food {
private int x;
private int y;
private static Random rnd = new Random();
private Food(int x, int y) {
this.x = x;
this.y = y;
}
public static Food createRandomFood(int width, int height) {
return createFood(getRandomInt(width), getRandomInt(height));
}
private static int getRandomInt(int limit) {
return Math.abs(rnd.nextInt() % limit);
}
private static Food createFood(int x, int y) {
return new Food(x, y);
}
/**
* Get the x coordinate of the base location of this instance.
*/
public int getX() {
return x;
}
/**
* Get the y coordinate of the base location of this instance.
*/
public int getY() {
return y;
}
/** Paint this instance onto the specified Graphics context. */
public synchronized void paint(Graphics g) {
int gn = GreedSnake.NODE_SIZE;
int FoodColor = 0x0000ff;
g.setColor(FoodColor);
g.fillRect(this.getX() * gn, this.getY() * gn, gn, gn);
}
}
// 节点对象类
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -