加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Bloodstream.java 2.36 KB
一键复制 编辑 原始数据 按行查看 历史
卢嘉明 提交于 2020-06-20 22:52 . update Bloodstream.java.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The bloodstream is the setting for our White Blood Cell scenario.
* It's a place where blood cells, bacteria and viruses float around.
*
* @author Michael Kölling
* @version 0.1
*/
public class Bloodstream extends World
{
/**
* Constructor: Set up the starting objects.
*/
public Bloodstream()
{
super(780, 360, 1);
prepare();
addBorder();
addText(0,2000);
}
/**
* Create new floating objects at irregular intervals.
*/
public void act()
{
Bacteria bacteria=new Bacteria();
Virus virus=new Virus();
Redcell redcell=new Redcell();
if (Greenfoot.getRandomNumber(100) < 3)
{
addObject(bacteria, 779, Greenfoot.getRandomNumber(360));
}
if (Greenfoot.getRandomNumber(100) < 1)
{
addObject(virus, 779, Greenfoot.getRandomNumber(360));
}
if (Greenfoot.getRandomNumber(100) < 5)
{
addObject(redcell, 779, Greenfoot.getRandomNumber(360));
}
addBorder();
}
/**
* Prepare the world for the start of the program. In this case: Create
* a white blood cell and the lining at the edge of the blood stream.
*/
private void prepare()
{
WhiteCell whitecell = new WhiteCell();
addObject(whitecell, 83, 179);
Lining lining = new Lining();
addObject(lining, 126, 1);
Lining lining2 = new Lining();
addObject(lining2, 342, 5);
Lining lining3 = new Lining();
addObject(lining3, 589, 2);
Lining lining4 = new Lining();
addObject(lining4, 695, 5);
Lining lining5 = new Lining();
addObject(lining5, 114, 359);
Lining lining6 = new Lining();
addObject(lining6, 295, 353);
Lining lining7 = new Lining();
addObject(lining7, 480, 358);
Lining lining8 = new Lining();
addObject(lining8, 596, 359);
Lining lining9 = new Lining();
addObject(lining9, 740, 354);
}
private void addBorder(){
addObject(new Border(), 780, 180);
addObject(new Border(), 0, 180);
}
public void addText(int score, int time){
showText("Score:"+score,80,20);
showText("Time:"+time,700,20);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化