我一個簡單的馬里奧側滾動工作方式滾動(),當我嘗試調用滾動對象滾動()方法,我得到無法找到符號 - 方法滾動( )錯誤拋出。請幫忙!
這裏是Subworld文件找不到符號 -
import greenfoot.*;
import java.util.ArrayList;
/**
* Write a description of class MarioWorld here.
*
* @author (your name)
* @version (a version number or a
public class MarioWorld extends World
{
ArrayList<MovingActor> moving = new ArrayList<MovingActor>();
ArrayList<Actor> things = new ArrayList<Actor>();
Message messagebox = new Message("");
/**
* Constructor for objects of class MarioWorld.
*
*/
public MarioWorld()
{
super(800, 600, 1);
for(int i = 0; i < 40; i++)
{
things.add(new GreenApple());
things.add(new Shamrock());
}
for(int i = 0; i<8;i++)
things.add(new Brick());
moving.add(new Mario());
for(int r = 0;r < things.size();r++)
{
addObject(things.get(r),Greenfoot.getRandomNumber(800),Greenfoot.getRandomNumber(600));
}
}
public void act()
{
for(int i = 0;i < things.size();i++)
{
things.get(i).scroll();
}
addObject(moving.get(0),15,300);
moving.get(0).worldact();
}
}
`
這裏是3個滾動類別之一(它們是除名稱/圖片相同
import greenfoot.*;
public class Shamrock extends Actor implements Scrollable
{
/**
* Act - do whatever the Shamrock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Actor worldact()
{
scroll();
return this;
}
public void scroll()
{
int x = getX();
int y = getY();
if(x <= 0)
x = 800;
x -= 6;
setLocation(x,y);
}
}
這裏是 '可滾動' 接口
import greenfoot.*;
public interface Scrollable
{
public void scroll();
}
我不打算回答,但我想你可能要明確施放,例如'((Shamrock)things.get(i)).roll();' –
是演員一類實現可滾動? –