代码拉取完成,页面将自动刷新
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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。