加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Lobster.java 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
陶鸿南 提交于 2021-04-19 08:47 . add files.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Lobster here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Lobster extends Actor
{
/**
* Act - do whatever the Lobster wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int count=0;
public void act()
{
move(5);
randomTurn();
turnAtEdge();
eat();
}
public void eat(){
if(isTouching(Crab.class)){
removeTouching(Crab.class);
Greenfoot.playSound("slurp.wav");
count++;
}
if(count==1){
World w = getWorld();
GreenfootImage bg = w.getBackground();
bg.setFont(new Font(true,true,150));
bg.setColor(new Color(250,0,0));
bg.drawString("失败!",120,300);
Greenfoot.stop();
}
}
public void turnAtEdge(){
if (isAtEdge()){
turn(15);
}
}
public void randomTurn(){
if(Greenfoot.getRandomNumber(100)<40){
turn(Greenfoot.getRandomNumber(30)-15);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化