加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Crab.java 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
陶鸿南 提交于 2021-04-19 09:14 . add files
import greenfoot.*;
/**
* This class defines a crab. Crabs live on the beach.
*/
public class Crab extends Actor
{
GreenfootImage image1 = new GreenfootImage("crab.png");
GreenfootImage image2 = new GreenfootImage("crab2.png");
int count = 0;
public Crab(){
setImage(image1);
}
public void act()
{
<<<<<<< HEAD
keyControl();
move(4);
eat();
switchImage();
}
public void switchImage(){
if(getImage()==image1){
setImage(image2);
}
else
setImage(image1);
}
public void keyControl(){
if(Greenfoot.isKeyDown("a")){
turn(-5);
}
if(Greenfoot.isKeyDown("d")){
turn(5);
}
if(Greenfoot.isKeyDown("w")){
move(5);
}
if(Greenfoot.isKeyDown("d")){
turn(-10);
}
}
public void eat(){
if(isTouching(Worm.class)){
removeTouching(Worm.class);
Greenfoot.playSound("slurp.wav");
count++;
World w = getWorld();
w.showText("吃虫数:"+count,50,100);
}
if(count==3){
World w = getWorld();
GreenfootImage bg = w.getBackground();
bg.setFont(new Font(true,true,150));
bg.setColor(new Color(0,255,0));
bg.drawString("成功!",120,300);
Greenfoot.stop();
}
=======
move(2);
>>>>>>> abc9c9eaaa8241ff0b5379e72755922233de5434
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化