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

2015/1/19

Create Target Field

lupus lupus

2015/1/19

#
Hello everybody, I'm programming a game similar to "Sokoban". In this game the actor has to push boxes around and place them on a "target field". Now I want to implement a method, which recognizes, when all the boxes are placed on the target fields. For example: We have four boxes and therefore four target fields. The actor has to push one box after the others and place them on the four target fields. After the last box is placed on the last free target field, the system should print out the line "You won". I would appreciate it if anybody can help me. Thanks.
danpost danpost

2015/1/20

#
First, you will need a public method in the target class that returns a boolean value indicating whether a box is upon it or not. Then in the act method of your subclass of World, you will call that method on all targets in the world. If any return false, you can break out of the loop and do nothing. If all return true, then the level was completed and you do what needs to be done at that point. I have a Kara Hexabon scenario which can be used as an example of this.
lupus lupus

2015/1/25

#
Now it works - thanks @dan! My problem was, that I first implemented the act method not in the subclass of my world, but in the actor class.
You need to login to post a reply.