Advertisement
Guest User

TicTacToes

a guest
Apr 20th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module TicTacToe
  2.     Dim map(,) As Integer = New Integer(2, 2) {{2, 0, 1}, {0, 2, 1}, {0, 0, 1}}
  3.     Dim LastMsg As String
  4.  
  5.     Public Function GetMap() As Integer(,)
  6.         Return map
  7.     End Function
  8.  
  9.     Public Function PerformCheck() As Integer
  10.         Dim Result As Integer = 0
  11.         Dim RowCheck(2) As Integer
  12.  
  13.         For i As Integer = 1 To 2
  14.  
  15.             'horizontal
  16.            For r As Integer = 0 To 2
  17.                 For s As Integer = 0 To 2
  18.                     RowCheck(s) = map(r, s)
  19.                 Next
  20.                 If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
  21.                     Result = i
  22.                     Exit For
  23.                 End If
  24.             Next
  25.  
  26.             'vertical
  27.            For s As Integer = 0 To 2
  28.                 For r As Integer = 0 To 2
  29.                     RowCheck(r) = map(r, s)
  30.                 Next
  31.                 If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
  32.                     Result = i
  33.                     Exit For
  34.                 End If
  35.             Next
  36.  
  37.             'diagonal \
  38.            For s As Integer = 0 To 2
  39.                 RowCheck(s) = map(s, s)
  40.             Next
  41.             If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
  42.                 Result = i
  43.                 Exit For
  44.             End If
  45.  
  46.             'diagonal /
  47.            Dim TempLine As Integer = 0
  48.             For s As Integer = 2 To 0 Step -1
  49.                 RowCheck(TempLine) = map(s, TempLine)
  50.                 TempLine = TempLine + 1
  51.             Next
  52.             If (RowCheck(0) = i And RowCheck(1) = i And RowCheck(2) = i) Then
  53.                 Result = i
  54.                 Exit For
  55.             End If
  56.         Next
  57.  
  58.         Return Result
  59.     End Function
  60.  
  61.     Public Sub StartGame()
  62.         If (Form1.ComboBox1.SelectedItem = "PvP") Then
  63.             Form1.Button1.Enabled = False
  64.             Form1.Button2.Enabled = True
  65.             Form1.ComboBox1.Enabled = False
  66.  
  67.         ElseIf (Form1.ComboBox1.SelectedItem = "CPU") Then
  68.             Form1.Button1.Enabled = False
  69.             Form1.ComboBox1.Enabled = False
  70.             Form1.Button2.Enabled = True
  71.  
  72.         Else
  73.             LogMsg("Please Select a gamemode.")
  74.         End If
  75.     End Sub
  76.  
  77.     Public Sub ResetGame()
  78.         map = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
  79.         Form1.Button1.Enabled = True
  80.         Form1.Button2.Enabled = False
  81.         Form1.ComboBox1.Enabled = True
  82.         Form1.ReDraw()
  83.  
  84.     End Sub
  85.  
  86.     Private Sub LogMsg(msg As String)
  87.         If Not (LastMsg = msg) Then
  88.             Form1.Label1.Text = msg
  89.             Form2.ListBox1.Items.Add(My.Computer.Clock.GmtTime & " " & msg)
  90.         End If
  91.         LastMsg = msg
  92.     End Sub
  93.  
  94. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement