28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10 ■ Directing the Cast of Actors: Creating a Casting Director Engine and Creating the Bagel Actor Class<br />

The easiest of these three methods to write is the .getRemovedActors() method, which simply uses a return<br />

keyword to pass the entire HashSet Set object to a calling entity. This provides access to REMOVED_ACTORS<br />

to other methods, such as the ones we will be writing later on in this section. The <strong>Java</strong> code should look just like this:<br />

public Set getRemovedActors() {<br />

return REMOVED_ACTORS;<br />

}<br />

The next method we’ll need to code is the most complicated as well as the most often used, as it will be the one<br />

you use when something in your cast has changed: for instance, a killed enemy, such as an InvinciBagel, a spent<br />

projectile, such as a bullet, consumed food, such as a ball of cream cheese, or found treasure, such as a gift box.<br />

The .addToRemovedActors() method uses the if-else statement, to ascertain if multiple Actor objects have been<br />

passed in the parameter list (the first or if part of the construct) or if just one Actor object needs to be removed (the<br />

second or else part of the construct). The first part of the if-else statement uses the .length() method to ascertain if<br />

more than one Actor objects has been passed into the method call parameter list using if(actors.length > 1) since<br />

an Actor... parameter allows more than one Actor object to be submitted to the method, as seen in Figure 10-9.<br />

Figure 10-9. Add .getRemovedActors(), .addToRemovedActors(), and .resetRemovedActors() method structures<br />

220<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!