Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module TicTacToe
- Dim map(,) As Integer = New Integer(2, 2) {{2, 0, 1}, {0, 2, 1}, {0, 0, 1}}
- Dim LastMsg As String
- Public Function GetMap() As Integer(,)
- Return map
- End Function
- Public Function PerformCheck() As Integer
- Dim Result As Integer = 0
- Dim RowCheck(2) As Integer
- For i As Integer = 1 To 2
- 'horizontal
- For r As Integer = 0 To 2
- For s As Integer = 0 To 2
- RowCheck(s) = map(r, s)
- Next
- If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
- Result = i
- Exit For
- End If
- Next
- 'vertical
- For s As Integer = 0 To 2
- For r As Integer = 0 To 2
- RowCheck(r) = map(r, s)
- Next
- If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
- Result = i
- Exit For
- End If
- Next
- 'diagonal \
- For s As Integer = 0 To 2
- RowCheck(s) = map(s, s)
- Next
- If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
- Result = i
- Exit For
- End If
- 'diagonal /
- Dim TempLine As Integer = 0
- For s As Integer = 2 To 0 Step -1
- RowCheck(TempLine) = map(s, TempLine)
- TempLine = TempLine + 1
- Next
- If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
- Result = i
- Exit For
- End If
- Next
- Return Result
- End Function
- Public Sub StartGame()
- If (Form1.ComboBox1.SelectedItem = "PvP") Then
- Form1.Button1.Enabled = False
- Form1.Button2.Enabled = True
- Form1.ComboBox1.Enabled = False
- ElseIf (Form1.ComboBox1.SelectedItem = "CPU") Then
- Form1.Button1.Enabled = False
- Form1.ComboBox1.Enabled = False
- Form1.Button2.Enabled = True
- Else
- LogMsg("Please Select a gamemode.")
- End If
- End Sub
- Public Sub ResetGame()
- map = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
- Form1.Button1.Enabled = True
- Form1.Button2.Enabled = False
- Form1.ComboBox1.Enabled = True
- Form1.ReDraw()
- End Sub
- Private Sub LogMsg(msg As String)
- If Not (LastMsg = msg) Then
- Form1.Label1.Text = msg
- Form2.ListBox1.Items.Add(My.Computer.Clock.GmtTime & " " & msg)
- End If
- LastMsg = msg
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement