Game Development Reference
In-Depth Information
You can try to see if you can get the Sq variable to divulge the hidden contents
variable, but VB respects the private marking in the Square.vb file. Hidden in
this design is the idea that a rule will do only one kind of move. It turns out not to
be a limitation; all the rules we will write will boil down to either ''Flag a bunch of
squares'' or ''Click a bunch of squares'' but never both. This code asks the squares
to click and right-click themselves; that code does not exist. We will add that
capability to the Square class. Switch to the Square class and add the following
'Let code work our UI:
'A regular click of the square
Public Sub LeftClick()
Call Square_Click(Nothing, Nothing)
End Sub
'Let them mark a square with right-click
Public Sub RightClick()
'Create the arguments for a right-click
'All we care about is the button
Dim e As New System.Windows.Forms.MouseEventArgs(Windows.Forms.
MouseButtons.Right, 0, 0, 0, 0)
Call Square_MouseUp(Nothing, e)
End Sub
The Click event handler ignores its arguments, so we can safely pass it Nothing
for both of them. The MouseUp handler looks to see what button was pressed, so
we created a new mouse event arguments object with the correct button and
zeroes for all the numbers. We do not care about those numbers, and zero is a
safe value for them.
There are two types of cheating for game AI: The AI can know things that it
should not, or the AI can do things the player cannot. For this reason, there is a
very important design decision made here: The AI uses the same user interface as
the player, and is restricted to the same actions as the player. The AI has shims
between it and the player code, but those shims are very thin and know nothing
about the intent of what they transmit. In most commercial games, the shim is
usually between the player and the game because the AI can natively speak the
command language of the game. Besides preventing cheating, using common
code simplifies the evolution of the game by having only one command path
instead of two that must be kept synchronized.
Search Nedrilad ::

Custom Search