Game Development Reference
In-Depth Information
want it to write, or place, this code at the end of the current class structure), and then
click the Generate button at the bottom of this dialog, to generate the eight new
Boolean variable access method structures.
As you can see in Figure 12-3 , there are eight new methods at the bottom of your
InvinciBagel.java class. It is important to note that the .set() methods all use the Java
this keyword to set the Boolean variable that you pass in to the method to the up,
down, left, or right (private) variables. The .setUp() method, for instance, would look
like this:
public void setUp (boolean up) {
this .up = up;
}
Figure 12-3 . Place the cursor at the bottom of the class so that the four .set() and .is() methods are the last ones listed
In this case, the this.up refers to the private up variable inside the InvinciBagel ob-
ject (InvinciBagel class).
As you can see, this is the new (more complex, or at least more involved to put into
place, code-wise) way that we can now access the up variable without having to reach
across classes using a static modifier keyword and an import static declaration at the
top of the Bagel.java class, which as you will see a bit later, we no longer need to use.
Now that we have made our InvinciBagel class a bit more encapsulated (more
private, and less public) by declaring the Boolean variables to be private, and putting
 
 
Search WWH ::




Custom Search