代码拉取完成,页面将自动刷新
同步操作将从 吕焱飞/ants-start 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import greenfoot.*;
import java.util.Random;
/**
* A pile of food. The pile consists initially of 100 crumbs of food.
*
* @author Michael Kölling
* @version 1.2
*/
public class Food extends Actor
{
private static final int SIZE = 30;
private static final int HALFSIZE = SIZE / 2;
private static final Color color1 = new Color(160, 200, 60);
private static final Color color2 = new Color(80, 100, 30);
private static final Color color3 = new Color(10, 50, 0);
private static final Random randomizer = new Random();
private int crumbs = 100; // number of bits of food in this pile
/**
* Create a pile of food with an image depicting the amount.
*/
public Food()
{
updateImage();
}
/**
* Remove some food from this pile of food.
*/
public void takeSome()
{
crumbs = crumbs - 3;
if (crumbs <= 0) {
getWorld().removeObject(this);
}
else {
updateImage();
}
}
/**
* Update the image
*/
private void updateImage()
{
GreenfootImage image = new GreenfootImage(SIZE, SIZE);
for (int i = 0; i < crumbs; i++) {
int x = randomCoord();
int y = randomCoord();
image.setColorAt(x, y, color1);
image.setColorAt(x + 1, y, color2);
image.setColorAt(x, y + 1, color2);
image.setColorAt(x + 1, y + 1, color3);
}
setImage(image);
}
/**
* Returns a random number relative to the size of the food pile.
*/
private int randomCoord()
{
int val = HALFSIZE + (int) (randomizer.nextGaussian() * (HALFSIZE / 2));
if (val < 0)
return 0;
if (val > SIZE - 2)
return SIZE - 2;
else
return val;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。