首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与Greenfoot抗争

与Greenfoot抗争
EN

Stack Overflow用户
提问于 2015-01-18 20:23:53
回答 1查看 103关注 0票数 0

在作业中,我的Uni模块的题目是“问题解决和编程”。

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

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

我试图在互联网上找到一个解决方案,但是我不知道该搜索什么,尽管我的朋友们说,如果你有与编程相关的问题,使用stackoverflow是很好的,所以我想我会试一试,因为我会感谢一些帮助。

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

代码语言:javascript
复制
    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) ;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-01-18 20:27:19

key()中的多个int's没有设置为任何值。你不能就这样丢下他们。

代码语言:javascript
复制
    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 ; 

所以应该是这样的

代码语言:javascript
复制
int leftChange=4;

每一个都是。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28009602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档