Game Development Reference
In-Depth Information
The easiest of these three methods to write is the .getRemovedActors() method,
which simply uses a return keyword to pass the entire HashSet<Actor> Set object to a
calling entity. This provides access to REMOVED_ACTORS to other methods, such
as the ones we will be writing later on in this section. The Java code should look just
like this:
public Set getRemovedActors () {
return REMOVED_ACTORS ;
}
The next method we'll need to code is the most complicated as well as the most of-
ten used, as it will be the one you use when something in your cast has changed: for in-
stance, a killed enemy, such as an InvinciBagel, a spent projectile, such as a bullet,
consumed food, such as a ball of cream cheese, or found treasure, such as a gift box.
The .addToRemovedActors() method uses the if-else statement, to ascertain if
multiple Actor objects have been passed in the parameter list (the first or if part of the
construct) or if just one Actor object needs to be removed (the second or else part of
the construct). The first part of the if-else statement uses the .length() method to ascer-
tain if more than one Actor objects has been passed into the method call parameter list
using if(actors.length > 1) since an Actor... parameter allows more than one
Actor object to be submitted to the method, as seen in Figure 10-9 .
 
Search WWH ::




Custom Search