Game Development Reference
In-Depth Information
This type of error checking speeds development. It is faster to read an error message than it is to
rerun code in a debugger. We could even ensure that the second kind of error never happens by
having the FSM self-check for consistent data. That exercise is left for the student.
We have assembled all the basic parts. We are getting closer to the time, as
Dr. Frankenstein puts it, to ''give my creature life!'' We need to implement a
child class for each of the unique states and implement the transitions that will go
into our monster. Open the File menu and choose Save All; then add a new class
to the project. Name it HidingState.vb and type the following line of code inside
the class without pressing the Enter key.
Inherits BasicState
Now press Enter. VB adds the three routines called for by BasicState . If you look
back at BasicState , you see three MustOverride routines. One of the advantages
to the Common Language Runtime languages in Visual Studio such as Visual
Basic and C# is that the development environment has a deep understanding of
classes. IntelliSense exploits this same technology. The whole package is aimed at
speeding up development and reducing errors.
Because Visual Basic was kind enough to create the skeletons of our three rou-
tines, we should fill them in. In the Entry routine, add the following:
World.Say("This looks like a good hiding spot!")
In the ExitFunction routine, add the following:
World.Say("I can't stay hiding here.")
And in the Update function, add the following:
World.Say("Shhh! I'm hiding.")
At this point, we might want to do the transitions out of the class, but we have not
yet defined the classes at the other end of the transitions. We will start on those
other states now. Add another class and call it AttackState.vb. Make it inherit
from BasicState the same way you did for HidingState . In the Entry routine, add
the following:
World.Say("Grab weapon and shield!")
In the ExitFunction routine, add the following:
World.Say("I better put my weapon and shield away.")
Search Nedrilad ::

Custom Search