Game Development Reference
In-Depth Information
will do the minimum of both needed to get us to the point where we can begin
testing as we go.
Graphical Squares
Our graphical squares will be square buttons that have been adapted to our
needs. We need our squares to know their subscript. We do this because we will
split the graphical elements apart from the state data that drives them. The state
data is going to be copied and passed around and analyzed. We only need one
graphical board. People play Chess with one board in front of them and many
boards in their head; our code follows this pattern as well. Add a class to the
project and name it FaHButton.vb. Add the following code to the class:
Inherits Button
'Just a button, but we would love to know our subscript in the array
'so that we can tell others when we take events.
Private MySubscript As Integer
'When we drag/drop, we will have a hound number or -1 for fox.
Protected HoundNumber As Integer
That last bit is for later, when we will implement player moves using drag and
drop. The rest of the code makes our class act just like a regular button except in
the ways that we extend it. One way we do that is that our class will keep around a
subscript value. We want to make that value available to outside code, but we
never want it to change. Add the following code to do that:
Public ReadOnly Property Subscript() As Integer
Return MySubscript
End Get
End Property
This is the simplest possible property method; it returns our private value and
provides no way for outside code to change that value. We need a way to set it in
the first place, and we will do that when the class is created. Add the following
code to the class:
'We need a subscript value when we are created.
Public Sub New(ByVal ss As Integer)
MySubscript = ss
Search Nedrilad ::

Custom Search