S
Steven Smith
Vallerie, combining Kims logic for determining whether
an "X" or an "O" should be displayed & the rest of my
code makes a perfect working solution for the course
book. Liked the use of NOT kim cheers for that. anyway
heres the complete code for a working solution, any
improvments or comments are as always appreciated.
/////////
Dim mLabelCollection As New Collection()
Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub NewGameButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
NewGameButton.Click
'declare object & integer variables
Dim objLabel As Label
Dim intx As Integer
'looping to find Label controls on form &
clearing the contents
Do While intx < Controls.Count - 1
If TypeOf Controls.Item(intx) Is Label Then
objLabel = Controls.Item(intx)
objLabel.Text = ""
End If
intx = intx + 1
Loop
End Sub
Private Sub TicTacToeForm_Load(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'add controls to the form level collection
mLabelCollection.Add(Me.TTT1Label)
mLabelCollection.Add(Me.TTT2Label)
mLabelCollection.Add(Me.TTT3Label)
mLabelCollection.Add(Me.TTT4Label)
mLabelCollection.Add(Me.TTT5Label)
mLabelCollection.Add(Me.TTT6Label)
mLabelCollection.Add(Me.TTT7Label)
mLabelCollection.Add(Me.TTT8Label)
mLabelCollection.Add(Me.TTT9Label)
End Sub
'determine player turn & process the label clicks to
display the correct marker
Private Sub PlacePlayersMarker(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles TTT1Label.Click, TTT2Label.Click,
TTT3Label.Click, _
TTT4Label.Click, TTT5Label.Click,
TTT6Label.Click, _
TTT7Label.Click, TTT8Label.Click,
TTT9Label.Click
'determine which label has been clicked and
display players marker
'declare object variables
Dim ObjLabel As Label
'assign sender parameter to object variable
ObjLabel = sender
Static strPlayer As Boolean
strPlayer = Not strPlayer
If ObjLabel.Text = "" Then
If strPlayer Then
ObjLabel.Text = "X"
Else
ObjLabel.Text = "O"
End If
End If
End Sub
End Class
////////
an "X" or an "O" should be displayed & the rest of my
code makes a perfect working solution for the course
book. Liked the use of NOT kim cheers for that. anyway
heres the complete code for a working solution, any
improvments or comments are as always appreciated.
/////////
Dim mLabelCollection As New Collection()
Private Sub ExitButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub NewGameButton_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
NewGameButton.Click
'declare object & integer variables
Dim objLabel As Label
Dim intx As Integer
'looping to find Label controls on form &
clearing the contents
Do While intx < Controls.Count - 1
If TypeOf Controls.Item(intx) Is Label Then
objLabel = Controls.Item(intx)
objLabel.Text = ""
End If
intx = intx + 1
Loop
End Sub
Private Sub TicTacToeForm_Load(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'add controls to the form level collection
mLabelCollection.Add(Me.TTT1Label)
mLabelCollection.Add(Me.TTT2Label)
mLabelCollection.Add(Me.TTT3Label)
mLabelCollection.Add(Me.TTT4Label)
mLabelCollection.Add(Me.TTT5Label)
mLabelCollection.Add(Me.TTT6Label)
mLabelCollection.Add(Me.TTT7Label)
mLabelCollection.Add(Me.TTT8Label)
mLabelCollection.Add(Me.TTT9Label)
End Sub
'determine player turn & process the label clicks to
display the correct marker
Private Sub PlacePlayersMarker(ByVal sender As
Object, ByVal e As System.EventArgs) _
Handles TTT1Label.Click, TTT2Label.Click,
TTT3Label.Click, _
TTT4Label.Click, TTT5Label.Click,
TTT6Label.Click, _
TTT7Label.Click, TTT8Label.Click,
TTT9Label.Click
'determine which label has been clicked and
display players marker
'declare object variables
Dim ObjLabel As Label
'assign sender parameter to object variable
ObjLabel = sender
Static strPlayer As Boolean
strPlayer = Not strPlayer
If ObjLabel.Text = "" Then
If strPlayer Then
ObjLabel.Text = "X"
Else
ObjLabel.Text = "O"
End If
End If
End Sub
End Class
////////