Game Development Reference
In-Depth Information
If you want to make sure that the programming logic inside the while loop structure
is performed at least one time, use the do-while , as the evaluation is performed after
the loop logic is executed. If you want to make sure that the logic inside the loop is
only executed after (whenever) the evaluation is successful, which is the safer way to
code things, use the while loop structure.
JavaObjects:VirtualReality,UsingJava
Constructs
I saved the best, Java objects, for last, because they can be constructed in one fashion
or another using all the concepts that I have covered thus far in the chapter and because
they are the foundation of OOP language (in this case, Java 8). The fact is, everything
in the Java 8 programming language is based on Java's Object superclass (I like to call
it the masterclass), which is in the java.lang package, so an import statement for it
would reference java.lang.Object, the full pathname for the Java Object class.
Java objects are used to “virtualize” reality by allowing the objects you see all
around you in everyday life, or, in the case of your game, objects you are creating out
from your imagination, to be realistically simulated. This is done by using the data
fields (variables and constants) and the methods that you have been learning about in
this chapter. These Java programming constructs will make up the object characterist-
ics , or attributes (constants); states (variables); and behaviors (methods). The Java
class construct organizes each object definition (constants, variables, and methods) and
gives birth to an instance of that object, using the constructor method for the class that
designs and defines the object via the various Java keywords and constructs.
Creating an InvinciBagel Object: Attributes, States,
and Behavior
Let's put together an example of an InvinciBagel object that shows how constants
define characteristics, variables define states, and methods define behaviors. We will
do this using Java coding constructs that you have learned about thus far in the chapter,
including constants, variables, and methods that you have already defined, to some ex-
tent.
Search WWH ::




Custom Search