In the assignment I was given for my Uni module titled problem solving & programming.
I was given a scenario with errors in it and from reading the assignment the code listed below is where the errors are.
So far I found that in the public void key section of my code I keep getting the class expected error however since I'm a total programming newbie I have no idea how to fix the problem.
I have tried to find a solution on the internet however I have no idea what to search for though my friends said that using stackoverflow is great if you have problems related to programming so I thought I would give it a try as I would appreciate some help.
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) ;
}
}