Now we will return to implementing the defenses classes. To begin with, where should we create instances of defenses? Should we create them in the main program source file? Should they be created as fields in some class? Think about what uses defenses (assuming enemies don't have them yet). Also, remember that we want to use the up and down arrow keys to toggle through defenses. What is the best way to store the defense objects? As separate variables or as something else?
You could create defense objects in the main program, but it's probably better to create them in TMainShip because the main ship is the only thing that fires defenses. You could also store them as separate variables such as Blaster : TBlaster, DualBlaster : TDualBlaster, etc. But this would produce unecessary coding later on. The best way is to create a TList in TMainShip called Defenses. To keep track of the currently selected defense we'll create a field called DefenseIndex of type Integer and another one called Defense of type TDefense. We technically only need DefenseIndex, but it's nice to have both the index in the list as well as a reference to the object to ease coding later on. These fields should all be private because no other classes have any buisiness modifying these values. We can declare methods ChangeDefense and Fire so that the main program can have access to the defenses (i.e., so the main program can notify TMainShip when the spacebar or arrow keys are pressed).