代码拉取完成,页面将自动刷新
同步操作将从 吕焱飞/ants-start 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import greenfoot.*;
/**
* A hill full of ants.
*
* @author Michael Kölling
* @version 1.1
*/
public class AntHill extends Actor
{
/** Number of ants that have come out so far. */
private int ants = 0;
/** Total number of ants in this hill. */
private int maxAnts = 40;
/** Counter to show how much food have been collected so far. */
private Counter foodCounter;
/**
* Constructor for ant hill with default number of ants (40).
*/
public AntHill()
{
}
/**
* Construct an ant hill with a given number of ants.
*/
public AntHill(int numberOfAnts)
{
maxAnts = numberOfAnts;
}
/**
* Act: If there are still ants left inside, see whether one should come out.
*/
public void act()
{
if(ants < maxAnts)
{
if(Greenfoot.getRandomNumber(100) < 10)
{
getWorld().addObject(new Ant(this), getX(), getY());
ants++;
}
}
}
/**
* Record that we have collected another bit of food.
*/
public void countFood()
{
// if we have no food counter yet (first time) -- create it
if(foodCounter == null)
{
foodCounter = new Counter("Food: ");
int x = getX();
int y = getY() + getImage().getWidth()/2 + 8;
getWorld().addObject(foodCounter, x, y);
}
foodCounter.increment();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。