Chapter 3. Improving the Crab—more sophisticated programming

topics:

random behavior, keyboard control, sound

concepts:

dot notation, random numbers, defining methods, comments

In the previous chapter, we looked at the basics of starting to program our first game. There were many new things that we had to look at. Now, we will add more interesting behavior. Adding code will get a little easier from now on, since we have seen many of the fundamental concepts.

The first thing we shall look at is adding some random behavior.

Adding random behavior

In our current implementation, the crab can walk across the screen, and it can turn at the edge of our world. But when it walks, it always walks exactly straight. That is what we want to change now. Crabs don’t ...

Get Introduction to Programming with Greenfoot: Object–Oriented Programming in Java™ with Games and Simulations, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.