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

2014/1/7

About variabele next

Xaverua Xaverua

2014/1/7

#
I have a problem. I have to explain a little bit of the code of a programm. But I have a question because I don't understand a piece of the code. This is de code: Lichaam next; int x; int y; int rotation; public void act() { //Hij kijkt of de slang iets aanraakt. if(getIntersectingObjects(Lichaam.class).size() > 0) { ((Achtergrond)(getWorld())).GameOver(); return; //Hij gaat weer terug naar het vorige scherm. } else if (getX()==51 || getY()==51 || getX()==0 || getY()==0) //Het programma kijkt of de slang tegen de rand aankomt. { ((Achtergrond)(getWorld())).GameOver(); return; } There stands " Lichaam next; " lichaam is a variabele but where does next stand for? " If(getIntersectingObjects(Lichaam.class).size() > 0)" how does dis line work? Thanks in advance!
Gevater_Tod4711 Gevater_Tod4711

2014/1/7

#
next is the name of the variable. Lichaam is not the variable but the type of the variable. That means next is an object from the class Lichaam. The line "If(getIntersectingObjects(Lichaam.class).size() > 0)" checks whether there are one or more objects from the class Lichaam that intersect the object where this code line is in. So if there are one or more Lichaam objects touching the object this codeline is in the if clause is true and the following code is executed. Little improvement: if(!getIntersectingObjects(Lichaam.class).isEmpty()) would do the same but would probably have a better runtime.
Xaverua Xaverua

2014/1/7

#
Thanks! I fully understand the programm x
You need to login to post a reply.