3/20/2024 0 Comments Greenfoot sound input![]() When we called methods that were defined in our own class or inherited, it was enough to write the method name and parameter list. The notation used here is called dot notation. The limit 20 is excluded, so the number is actually in the range 0 to 19. For example, Greenfoot.getRandomNumber(20) will give us a random number between 0 and 20. It will then return a random number between 0 (zero) and the limit. This method, called getrandomnumber, expects a parameter that specifies the limit of the number. ![]() We can achieve this in Greenfoot by using random numbers: The Greenfoot environment itself has a method to give us a random number. ![]() Concept: When a method we wish to call is not in our own class or inherited, we need to specify the class or object that has the method before the method name, followed by a dot. Crabs don t always go in an exact straight line, so let us add a little random behavior: The crab should go roughly straight, but every now and then it should turn a little off course. But when it walks, it always walks exactly straight. 3.1 Adding random behavior In our current implementation, the crab can walk across the screen, and it can turn at the edge of our world. The first thing we shall look at is adding some random behavior. Adding code will get a little easier from now on, since we have seen many of the fundamental concepts. Now, we will add more interesting behavior. There were many new things that we had to look at. 1 3 Improving the Crab more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter, we looked at the basics of starting to program our first game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |