|
RHS |
Exercise 03
The WormChase game from chapter 2 can be downloaded in a version using the System.currentTimeMillis() timer (so it runs on a regular Java installation) here: Examples
As you've read chapter 2 you are familiar with the code - it's not a must to understand everything. If you get the idea and understand the big picture you'll get along.
As you know the game uses "wrap around" for the worm. If it leaves the frame to the left it shows up in the right side, if it leaves the frame upwards it shows up at the bottom etc.
Now change the code so the worm cannot leave the frame - i.e. no "wrap around". If the worm tries to go left of the left side the move should be ignored, if it tries to go right of the right side the move should be ignored etc.
BTW - if you think the worm is too long you can lower the MAXPOINTS constant in Worm.java.
And if you think the worm moves too fast (it does on my computer - it's nearly imposible to hit the bastard!) you can lower the constant DEFAULT_FPS in WormChase.java.