(SIPC) Analyzing Code Lesson
Analyzing Code
The Greenfoot website provides a place for programmers to upload completed programs to share with others. If you go to the Greenfoot.org website and click on Scenarios you can view a collection of different programs to play and download. Studying and analyzing other programs is a good way to learn how to program. If you are trying to create a space game where the spaceship fires lasers at an alien, studying a program with the same behavior lets you see how to perform the action. When you want to create a scoring system for your game, understanding how to use the Counter helper class makes it more efficient.
In this assignment you will analyze two different programs to see how the programs use helper classes and reuse code to make the program more efficient.
The first program is a Space Shooter game. The Ship is controlled with the keyboard arrow keys up and down. An Enemy craft is coming toward the ship at random locations on the Y. The Ship fires lasers at the Enemy. When the Enemy is hit, an explosion occurs and the Enemy craft disappears. The score increases when the Enemy is hit. Helper classes used in the program are Counter and Explosion. These classes can be reused in other classes.
The second program is a Chase game. Several objects are chasing each other. A crab is chasing the Algae. When it eats the algae, the score increases and a new Algae appears in a random place. The Shark is roaming around randomly. If it touches the Crab, the Crab will lose a life. The Octopus is falling down from the top of the program. If it touches the Crab, the Crab loses a life. When the Crab loses a certain number of lives the game is over. This classes uses the Counter and Animal Helper classes. The scoring is created using the Counter class. A LivesCounter subclass is created and the code from the Counter class is copied into it to create a separate display for lives. The Animal class methods are reused by all the other Animal subclasses.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION