在作业中,我的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) ;
}
}发布于 2015-01-18 20:27:19
key()中的多个int's没有设置为任何值。你不能就这样丢下他们。
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;每一个都是。
https://stackoverflow.com/questions/28009602
复制相似问题