0

在作业中,我获得了名为问题解决和编程的 Uni 模块。

我得到了一个有错误的场景,通过阅读作业,下面列出的代码就是错误所在。

到目前为止,我发现在我的代码的 public void key 部分中,我不断收到类预期错误,但是由于我是一个完全的编程新手,我不知道如何解决这个问题。

我试图在互联网上找到解决方案,但是我不知道要搜索什么,尽管我的朋友说如果您遇到与编程有关的问题,使用 stackoverflow 非常好,所以我想我会尝试一下,因为我会很感激一些帮助.

公共布尔canMove(int x,int y){

    Actor sand;
    sand=getOneObjectAtOffset(x,y,sandroad.class);

    //the section below checks if there is a block you can move to
    // if there is it sets sand to a vlaue otherwise it says null
    // The errors are in this section
    boolean flag=true;
    if (sand !=null)
    {
        flag=false;
    }
    return flag;
}
public void key()
{
   //Note 1: Down the page increase the y value and going to the right increases the x value
   //Note 2: Each block is 60 pixels wide and high 
    int leftChange=//choose the appropriate left step size ; 
    int rightChange=//choose the appropriate right step size ; 
    int upChange=//choose the appropriate up step size ; 
    int downChange=//choose the appropriate down step size ; 
    if (Greenfoot.isKeyDown("left"))
    {
        if (canMove(leftChange, 0)==true)
        setLocation(getX()+leftChange, getY()) ;
    }
    if (Greenfoot.isKeyDown("right"))
    {
       if (canMove(rightChange, 0)==true)
        setLocation(getX()+rightChange, getY()) ; 
    }
    if (Greenfoot.isKeyDown("up"))
    {
        if (canMove(0, upChange)==true)
        setLocation(getX(), getY()+upChange) ;
    }
    if (Greenfoot.isKeyDown("down"))
    {
        if (canMove(0, downChange)==true)
        setLocation(getX(), getY()+downChange) ;
    }
}
4

1 回答 1

0

好吧,倍数int's没有key()设置为任何东西。你不能就这样离开他们。

    int leftChange=//choose the appropriate left step size ; 
    int rightChange=//choose the appropriate right step size ; 
    int upChange=//choose the appropriate up step size ; 
    int downChange=//choose the appropriate down step size ; 

所以应该是这样的

int leftChange=4;

每一个人。

于 2015-01-18T12:27:19.123 回答