This site requires JavaScript, please enable it in your browser!
Greenfoot back
plsFast
plsFast wrote ...

2019/3/29

Can anybody help me?

plsFast plsFast

2019/3/29

#
So i want to have a method with the parameters x and y
public void name(int x, int y)
{
code
}
is there a way to limit x and y? For example that u cant type anything over 7? And the second question is is it possible to check if an object is already on specific koordinates? I want my player to check if another player stands on the next field before he moves (if the other player stands there he cant get on that field)
danpost danpost

2019/3/29

#
Do this: (1) move; (2) check touching other actor; and (3) if touching, move back.
plsFast plsFast

2019/3/29

#
isnt it possible to do it before moving?
plsFast plsFast

2019/3/30

#
can anyone answer that?
Super_Hippo Super_Hippo

2019/3/30

#
It does it in the same act-cycle. So it won't be visible there if it immediately moves back. Otherwise, you had to replicate the isTouching method instead of using the current location, use the one which it would have after moving. But that is really unnecessary. To the first question. You could exit your method with an error message if x or y are greater than 7.
public void name(int x, int y)
{
    if (x>7 || y>7)
    {
        System.out.println("Error in method <name>: values for parameters x and y should not exceed 7");
        return; //exit the method, do nothing
    }
    //actual code of the method
}
You need to login to post a reply.