找不到符号 - 方法滚动()

时间:2016-03-08 04:17:38

标签: java greenfoot

我正在研究一个简单的Mario侧卷轴,当我尝试调用滚动对象的 scroll()方法时,我得到找不到符号 - 方法滚动() 错误抛出。请帮忙!
 这是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);

    }
}

这是'Scrollable'界面

import greenfoot.*;

public interface Scrollable  
{
 public void scroll();
}

2 个答案:

答案 0 :(得分:0)

thingsActor的列表。 Actor未实现Scollable,但Shamrock不实现。 things.get(i)会返回Actor,而Scollable.scroll()没有Shamrock。您需要将其投放到Scollablethings。或者,您可以Shamrock列出@Html.ListBox("Group", (IEnumerable<SelectListItem>)ViewBag.Group, new { style = "width: 300px;" })

答案 1 :(得分:0)

此处movingobject ArrayList而非Shamrock的{​​{1}},因此您只能使用arraylistmoving类方法调用add()类对象remove() 1}} is generic type Safed

这里ArrayList . So, you need to remove the arraylist from the arraylist then only try to apply method object ((Shamrock)things.get(i)).scroll(); Scroll()`

使用此代码

things.get(i).scroll();

而不是 var dePath='/templates/img/'; var headerExist ='/templates/img/header.jpg'; var headerDimensions = sizeOf(headerExist); console.log(headerDimensions); req.file('file').upload({ dirname: require('path').resolve(dePath) },function (err, uploadedFiles) { if (err) return res.send(500, err); fs.unlink(headerExist, function (err) { if (err) return console.error(err); console.log("success!"); console.log('test'); fs.rename(uploadedFiles[0].fd, dePath+'headertemp.jpg', function (err) { if (err) return res.send(err); im.resize({ srcPath:dePath+'headertemp.jpg', dstPath: headerExist, width: headerDimensions.width }, function(err, stdout, stderr){ if (err) console.log(err + 'ff'); fs.unlink(dePath+'headertemp.jpg', function (err) { if (err) return console.error(err); console.log("success!"); console.log('test'); res.send('ok'); }); }); }); }); });