Guest User

Untitled

a guest
Dec 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     Public player_turn As Boolean = True
  3.     Public row1 As Integer
  4.     Public row2 As Integer
  5.     Public row3 As Integer
  6.     Public col1 As Integer
  7.     Public col2 As Integer
  8.     Public col3 As Integer
  9.     Public diag1 As Integer
  10.     Public diag2 As Integer
  11.     Public owin As Integer
  12.     Public xwin As Integer
  13.     Public tiecount As Integer
  14.     Public movecounter As Integer
  15.     'Player indicates who turn it is. True for x . False for O
  16.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  17.         nowplaying.Text = "X"
  18.     End Sub
  19.     Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
  20.         make_move(btn1)
  21.         keep_score(row1, col1, diag1)
  22.         check_win(row1, col1, diag1)
  23.         btn1.Enabled = False
  24.     End Sub
  25.     Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
  26.         make_move(btn2)
  27.         keep_score(row1, col2)
  28.         check_win(row1, col2)
  29.         btn2.Enabled = False
  30.     End Sub
  31.     Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
  32.         make_move(btn3)
  33.         keep_score(row1, col3, diag2)
  34.         check_win(row1, col3, diag2)
  35.         btn3.Enabled = False
  36.     End Sub
  37.     Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
  38.         make_move(btn4)
  39.         keep_score(row2, col1)
  40.         check_win(row2, col1)
  41.         btn4.Enabled = False
  42.     End Sub
  43.     Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
  44.         make_move(btn5)
  45.         keep_score(row2, col2)
  46.         btn5.Enabled = False
  47.         If player_turn = False Then
  48.             diag1 = diag1 + 1
  49.             diag2 = diag2 + 1
  50.         Else
  51.             diag1 = diag1 + 10
  52.             diag2 = diag2 + 10
  53.         End If
  54.         check_win(row2, col2)
  55.     End Sub
  56.     Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
  57.         make_move(btn6)
  58.         keep_score(row2, col3)
  59.         check_win(row2, col3)
  60.         btn6.Enabled = False
  61.     End Sub
  62.     Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
  63.         make_move(btn7)
  64.         keep_score(row3, col1, diag2)
  65.         check_win(row3, col1, diag2)
  66.         btn7.Enabled = False
  67.     End Sub
  68.     Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
  69.         make_move(btn8)
  70.         keep_score(row3, col2)
  71.         check_win(row3, col2)
  72.         btn8.Enabled = False
  73.     End Sub
  74.     Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
  75.         make_move(btn9)
  76.         keep_score(row3, col3, diag1)
  77.         check_win(row3, col3, diag1)
  78.         btn9.Enabled = False
  79.     End Sub
  80.     Private Sub Restart_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Restart_button.Click
  81.         btn1.Text = " "
  82.         btn2.Text = " "
  83.         btn3.Text = " "
  84.         btn4.Text = " "
  85.         btn5.Text = " "
  86.         btn6.Text = " "
  87.         btn7.Text = " "
  88.         btn8.Text = " "
  89.         btn9.Text = " "
  90.         player_turn = True
  91.         nowplaying.Text = "X"
  92.         row1 = 0
  93.         row2 = 0
  94.         row3 = 0
  95.         col1 = 0
  96.         col2 = 0
  97.         col3 = 0
  98.         diag1 = 0
  99.         diag2 = 0
  100.         movecounter = 0
  101.         winlabel.Text = " "
  102.         btn1.Enabled = True
  103.         btn2.Enabled = True
  104.         btn3.Enabled = True
  105.         btn4.Enabled = True
  106.         btn5.Enabled = True
  107.         btn6.Enabled = True
  108.         btn7.Enabled = True
  109.         btn8.Enabled = True
  110.         btn9.Enabled = True
  111.     End Sub
  112.     Function make_move(ByVal btn)
  113.         If player_turn = True Then
  114.             btn.Text = "X"
  115.             nowplaying.Text = "O"
  116.         Else
  117.             btn.Text = "O"
  118.             nowplaying.Text = "X"
  119.         End If
  120.         player_turn = Not player_turn
  121.         movecounter += 1
  122.         Return 0
  123.     End Function
  124.     Function keep_score(ByRef row As Integer, ByRef col As Integer, Optional ByRef diag As Integer = 0) As Integer
  125.         If player_turn = False Then
  126.             row = row + 1
  127.             col = col + 1
  128.             diag = diag + 1
  129.         Else
  130.             row = row + 10
  131.             col = col + 10
  132.             diag = diag + 10
  133.         End If
  134.         Return 0
  135.     End Function
  136.     Function check_win(ByRef row As Integer, ByRef col As Integer, Optional ByRef diag As Integer = 0) As Integer
  137.         If row = 3 Or col = 3 Or diag = 3 Then
  138.             winlabel.Text = "Congratulations! X has won!"
  139.             xwin += 1
  140.             xwin_box.Text = xwin
  141.             disable_buts()
  142.         ElseIf row = 30 Or col = 30 Or diag = 30 Then
  143.             winlabel.Text = "Congratulations! O has won!"
  144.             owin += 1
  145.             owin_box.Text = owin
  146.             disable_buts()
  147.         End If
  148.         If movecounter = 9 Then
  149.             winlabel.Text = "A tie has occured"
  150.             tiecount += 1
  151.             tiebox.Text = tiecount
  152.         End If
  153.         Return 0
  154.     End Function
  155.     Function disable_buts() As Integer
  156.         btn1.Enabled = False
  157.         btn2.Enabled = False
  158.         btn3.Enabled = False
  159.         btn4.Enabled = False
  160.         btn5.Enabled = False
  161.         btn6.Enabled = False
  162.         btn7.Enabled = False
  163.         btn8.Enabled = False
  164.         btn9.Enabled = False
  165.         Return 0
  166.     End Function
  167. End Class
Add Comment
Please, Sign In to add comment