Game Development Reference
In-Depth Information
buttons to select a class and see the number of hit points change to the correct
value. Change the Level and Class settings and verify that the code properly
handles user input. Stop debugging so that you can edit the code.
We need our code to wake up with a class selected. The Level control wakes up
sane, but the Class settings do not. We could set the Checked property to true for
one of the radio buttons using the Properties window, but there is a better way.
Add the following line to the empty GameForm_Load routine:
MageRadio.Checked = True
Now when our code wakes up, it will check the MageRadio radio button. This
means that the radio buttons will appear to the user to wake up sane. One button
will be selected. Run the application again. Notice that the maximum number of
hit points is shown as 4 and not as 888. We did not directly change the label text,
so why did it change? When our code selected the radio button, the system did as
we asked and selected the button. The system also did as it always does and fired
the CheckedChanged event for the control. The event handler we added for that
event of that control ran, setting the die size to 4 and calling ComputeHitPoints .
ComputeHitPoints set the label for us, using the formula. Not only will user
interaction cause events to be fired, but actions by our code cause them as well.
We exploited the capability of our code to raise events in order to let it use
the regular code for operation to also work for initialization. This cut down
on the coding and the complexity. We eliminated a hidden dependency between
the formula and the initialization code. Getting rid of special initialization code
gets rid of potential bugs; there are no bugs in code that is not there.
Chapter Summary
In this chapter, we established a working definition for game AI. Game AI must
act intelligently in the face of changing conditions. Unlike physics, game AI has
choices when making its decisions. This chapter also gave us our first project,
providing a grounding in Visual Basic that we will build upon in future chapters.
Chapter Review
Answers are in the appendix.
1. What are the three parts to our definition of game AI?
2. Why is game physics not game AI?
 
 
 
Search Nedrilad ::




Custom Search