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

2013/5/19

Jigsaw puzzle help?

Jin-Ho Jin-Ho

2013/5/19

#
Hello, I am wanting to make a sort of jigsaw puzzle and I am not sure how to describe my problem however I will try my best explaining. What kind of code do I have to write so the program checks where the current location of an object is and according to its location does whatever it needs to? (so in my case, check where all the objects are and if they are all correct, go to the next world) I am sorry I am still new to java programming. I would appreciate any kind of help. Thank you
Gevater_Tod4711 Gevater_Tod4711

2013/5/19

#
To check an objects location you can use getX() and getY(). To check whether the object is at the right location you need to know what the right location is. If the target location is known in the object you can check whether the location is right like this:
int targetX = 50;
int targetY = 50;
//of course you can use any other value here;

public boolean atTargetLocation() {
    return getX() == targetX && getY() == targetY;
}
Jin-Ho Jin-Ho

2013/5/19

#
Thank you very much for your help!
You need to login to post a reply.