Building Mobile Applications
ctrl.Enabled = False Exit For
End If End If End If
Next
End While End Sub
Private Sub TicTacToe_Click(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles btn00.Click, btn20.Click, btn10.Click, _ btn01.Click, btn21.Click, btn11.Click, btn02.Click, btn22.Click, btn12.Click
CorrectEnabledState(False)
Application.DoEvents() ‘Allows the screen to refresh CType(sender, Button).Text = “X”
If IsGameOver() Then MsgBox(“Game Over”)
Else
lblMessages.Text = “Computer selecting ...” Application.DoEvents() ‘Allows the screen to refresh ComputerPlay()
If IsGameOver() Then MsgBox(“Game Over”)
Else
lblMessages.Text = “Select your next position ...” CorrectEnabledState()
End If End If
End Sub
Sub Winner(ByVal strWinner As String) Dim strMessage As String
If strWinner = “X” Then strMessage = “You win!!”
ElseIf strWinner = “O” Then strMessage = “Computer wins!!”
Else
strMessage = strWinner End If
lblMessages.Text = strMessage End Sub
Function IsGameOver() As Boolean
If btn00.Text = btn01.Text And btn01.Text = btn02.Text And _
btn02.Text <> String.Empty Then
‘Winner on top Row
Call Winner(btn00.Text)
Return True
End If
If btn10.Text = btn11.Text And btn11.Text = btn12.Text And _ btn12.Text <> String.Empty Then
‘Winner on middle Row Call Winner(btn10.Text)