Game Development Reference
In-Depth Information
also need to extend the game so that we can listen to the AI think. The AI will not
do anything if we fail to add code that runs the AI.
The AI Needs to Think Out Loud
We start by giving the AI a place to tell us what it is thinking. The extra space on
the right side of the control panel makes a perfect place for messages. Bring up
the Design view of PlayingField ; then follow these steps:
1. Drag a TextBox control from the Toolbox and drop it to the right of the
controls already there.
2. Change its Name property to ThoughtsTextBox.
3. Set the Multiline property to True and resize the control to fill the available
space.
4. Set the ReadOnly property to True.
Later on, you may wish to add a vertical scrollbar to the control by setting the
ScrollBars property to Vertical. We will create two routines that manipulate this
control. Both will add text, but one of them will clear out the old text first. Switch
to Code view and create a new region for the AI. Do not put this region inside any
other regions. Add code to it to get the following:
#Region "AI Related"
'Let it speak - clear old stuff
Public Sub FirstThought(ByVal someThought As String)
ThoughtsTextBox.Clear()
MoreThoughts(someThought)
End Sub
'Say what it is thinking
Public Sub MoreThoughts(ByVal someThought As String)
ThoughtsTextBox.AppendText(someThought & vbCrLf)
End Sub
#End Region
Our AI now has a place to say things. We should clear what it is thinking when we
start a new game. Add the following line of code to the NewGame routine just above
where the cursor is returned to normal:
'Remove thoughts from last game
ThoughtsTextBox.Clear()
 
Search Nedrilad ::




Custom Search