0

課題では、問題解決とプログラミングというタイトルの大学モジュールを与えられました。

エラーのあるシナリオが与えられました。割り当てを読んで、以下にリストされているコードがエラーの場所です。

これまでのところ、コードの public void key セクションでクラスの予期されるエラーが発生し続けることがわかりましたが、私は完全なプログラミング初心者であるため、問題を修正する方法がわかりません。

私はインターネットで解決策を見つけようとしましたが、何を検索すればよいかわかりませんが、プログラミングに関連する問題がある場合、stackoverflow を使用することは素晴らしいと友達が言ったので、助けていただければ幸いです。 .

public boolean 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'skey()何にも設定されていません。彼らをそのままにしておくことはできません。

    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 に答える