Game Development Reference
In-Depth Information
Creating a HashSet Object: REMOVED_ACTORS
Data Store Set<Actor>
Now let's create our third Set<Actor> HashSet data store object, and let's call it
REMOVED_ACTORS , since it will be used to hold a collection of Actor objects that
have been removed from the current Stage. This Set<Actor> object will hold all of the
Actor objects that for whatever reason need to be removed from the CURRENT_CAST
List. The REMOVED_ACTORS data store (data set) will have three associated meth-
ods.
The .getRemovedActors() method will return the REMOVED_ACTORS object,
the .addToRemovedActors() will be the “core” method that will add Actor objects to
the REMOVED_ACTORS Set<Actor> object as things happen during game play
(finding treasure, killing enemies, etc.) that eliminate an Actor object from the Stage
and Scene, and the .resetRemovedActors() that will use the .removeAll() method to re-
move Actors from the CURRENT_CAST ArrayList<Actor> object, and then reset the
REMOVED_ACTORS data set, by using the .clear() method call on the
REMOVED_ACTORS HashSet object. The code, seen in Figure 10-8 , needed to de-
clare and instantiate the HashSet object using the Java new keyword, looks like this:
private final Set<Actor> REMOVED_ACTORS = new HashSet<>();
Figure 10-8 . Add a private final Set named REMOVED_ACTORS and use the Java new keyword to create a
HashSet<>
 
 
Search WWH ::




Custom Search