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

2011/11/7

Help with getNeighbours

ajh267 ajh267

2011/11/7

#
i am trying to make a robot maze with a getNeighbours method. i want to make the robot see if there are any foot prints or walls around them and if so act. it will always be true because of how act is written. i just need help with how to write/understand getNeighbours.
davmac davmac

2011/11/8

#
Briefly, you first want to import the List interface (at the top of your class):
import java.util.List;
Then you do something like:
List<Wall> l = (List<Wall>) getNeighbours(1, true, Wall.class);  // get walls immediately surrounding me
for (Wall w : l) {
    // do something with the wall 'w'...
    // ...
}
Hopefully that's enough to get you started!
You need to login to post a reply.