Guest User

Untitled

a guest
Jan 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.05 KB | None | 0 0
  1. Public Class Form1
  2.     Dim turn As Integer
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         turn = 1
  5.     End Sub
  6.     Private Sub win()
  7.         If Button1.Text = "x" And Button2.Text = "x" And Button3.Text = "x" Then
  8.             MsgBox("jogador X ganhou!")
  9.             Label5.Text += 1
  10.             Call disablebuttons()
  11.         End If
  12.         If Button4.Text = "x" And Button5.Text = "x" And Button6.Text = "x" Then
  13.             MsgBox("jogador X ganhou!")
  14.             Label5.Text += 1
  15.             Call disablebuttons()
  16.         End If
  17.         If Button7.Text = "x" And Button8.Text = "x" And Button9.Text = "x" Then
  18.             MsgBox("jogador X ganhou!")
  19.             Label5.Text += 1
  20.             Call disablebuttons()
  21.         End If
  22.         If Button1.Text = "x" And Button4.Text = "x" And Button7.Text = "x" Then
  23.             MsgBox("jogador X ganhou!")
  24.             Label5.Text += 1
  25.             Call disablebuttons()
  26.         End If
  27.         If Button2.Text = "x" And Button5.Text = "x" And Button8.Text = "x" Then
  28.             MsgBox("jogador X ganhou!")
  29.             Label5.Text += 1
  30.             Call disablebuttons()
  31.         End If
  32.         If Button3.Text = "x" And Button6.Text = "x" And Button9.Text = "x" Then
  33.             MsgBox("jogador X ganhou!")
  34.             Label5.Text += 1
  35.             Call disablebuttons()
  36.         End If
  37.         If Button1.Text = "x" And Button5.Text = "x" And Button9.Text = "x" Then
  38.             MsgBox("jogador X ganhou!")
  39.             Label5.Text += 1
  40.             Call disablebuttons()
  41.         End If
  42.         If Button3.Text = "x" And Button5.Text = "x" And Button7.Text = "x" Then
  43.             MsgBox("jogador X ganhou!")
  44.             Label5.Text += 1
  45.             Call disablebuttons()
  46.         End If
  47.  
  48.  
  49.  
  50.         If Button1.Text = "o" And Button2.Text = "o" And Button3.Text = "o" Then
  51.             MsgBox("jogador o ganhou!")
  52.             Label6.Text += 1
  53.             Call disablebuttons()
  54.         End If
  55.         If Button4.Text = "o" And Button5.Text = "o" And Button6.Text = "o" Then
  56.             MsgBox("jogador o ganhou!")
  57.             Label6.Text += 1
  58.             Call disablebuttons()
  59.         End If
  60.         If Button7.Text = "o" And Button8.Text = "o" And Button9.Text = "o" Then
  61.             MsgBox("jogador o ganhou!")
  62.             Label6.Text += 1
  63.             Call disablebuttons()
  64.         End If
  65.         If Button1.Text = "o" And Button4.Text = "o" And Button7.Text = "o" Then
  66.             MsgBox("jogador o ganhou!")
  67.             Label6.Text += 1
  68.             Call disablebuttons()
  69.         End If
  70.         If Button2.Text = "o" And Button5.Text = "o" And Button8.Text = "o" Then
  71.             MsgBox("jogador o ganhou!")
  72.             Label6.Text += 1
  73.             Call disablebuttons()
  74.         End If
  75.         If Button3.Text = "o" And Button6.Text = "o" And Button9.Text = "o" Then
  76.             MsgBox("jogador o ganhou!")
  77.             Label6.Text += 1
  78.             Call disablebuttons()
  79.         End If
  80.         If Button1.Text = "o" And Button5.Text = "o" And Button9.Text = "o" Then
  81.             MsgBox("jogador o ganhou!")
  82.             Label6.Text += 1
  83.             Call disablebuttons()
  84.         End If
  85.         If Button3.Text = "o" And Button5.Text = "o" And Button7.Text = "o" Then
  86.             MsgBox("jogador o ganhou!")
  87.             Label6.Text += 1
  88.             Call disablebuttons()
  89.         End If
  90.     End Sub
  91.     Private Sub disablebuttons()
  92.         Button1.Enabled = False
  93.         Button2.Enabled = False
  94.         Button3.Enabled = False
  95.         Button4.Enabled = False
  96.         Button5.Enabled = False
  97.         Button6.Enabled = False
  98.         Button7.Enabled = False
  99.         Button8.Enabled = False
  100.         Button9.Enabled = False
  101.  
  102.     End Sub
  103.  
  104.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  105.         If turn = 1 Then
  106.             Button1.Text = "x"
  107.             Label2.Text = "o"
  108.         Else
  109.             Button1.Text = "o"
  110.             Label2.Text = "x"
  111.         End If
  112.         turn += 1
  113.         If turn > 2 Then
  114.             turn = 1
  115.         End If
  116.         Call win()
  117.         Button1.Enabled = False
  118.     End Sub
  119.  
  120.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  121.         If turn = 1 Then
  122.             Button2.Text = "x"
  123.             Label2.Text = "o"
  124.         Else
  125.             Button2.Text = "o"
  126.             Label2.Text = "x"
  127.         End If
  128.         turn += 1
  129.         If turn > 2 Then
  130.             turn = 1
  131.         End If
  132.         Call win()
  133.         Button2.Enabled = False
  134.     End Sub
  135.  
  136.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  137.         If turn = 1 Then
  138.             Button3.Text = "x"
  139.             Label2.Text = "o"
  140.         Else
  141.             Button3.Text = "o"
  142.             Label2.Text = "x"
  143.         End If
  144.         turn += 1
  145.         If turn > 2 Then
  146.             turn = 1
  147.         End If
  148.         Call win()
  149.         Button3.Enabled = False
  150.     End Sub
  151.  
  152.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  153.         If turn = 1 Then
  154.             Button4.Text = "x"
  155.             Label2.Text = "o"
  156.         Else
  157.             Button4.Text = "o"
  158.             Label2.Text = "x"
  159.         End If
  160.         turn += 1
  161.         If turn > 2 Then
  162.             turn = 1
  163.         End If
  164.         Call win()
  165.         Button4.Enabled = False
  166.     End Sub
  167.  
  168.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  169.         If turn = 1 Then
  170.             Button5.Text = "x"
  171.             Label2.Text = "o"
  172.         Else
  173.             Button5.Text = "o"
  174.             Label2.Text = "x"
  175.         End If
  176.         turn += 1
  177.         If turn > 2 Then
  178.             turn = 1
  179.         End If
  180.         Call win()
  181.         Button5.Enabled = False
  182.     End Sub
  183.  
  184.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  185.         If turn = 1 Then
  186.             Button6.Text = "x"
  187.             Label2.Text = "o"
  188.         Else
  189.             Button6.Text = "o"
  190.             Label2.Text = "x"
  191.         End If
  192.         turn += 1
  193.         If turn > 2 Then
  194.             turn = 1
  195.         End If
  196.         Call win()
  197.         Button6.Enabled = False
  198.     End Sub
  199.  
  200.     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  201.         If turn = 1 Then
  202.             Button7.Text = "x"
  203.             Label2.Text = "o"
  204.         Else
  205.             Button7.Text = "o"
  206.             Label2.Text = "x"
  207.         End If
  208.         turn += 1
  209.         If turn > 2 Then
  210.             turn = 1
  211.         End If
  212.         Call win()
  213.         Button7.Enabled = False
  214.     End Sub
  215.  
  216.     Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  217.         If turn = 1 Then
  218.             Button8.Text = "x"
  219.             Label2.Text = "o"
  220.         Else
  221.             Button8.Text = "o"
  222.             Label2.Text = "x"
  223.         End If
  224.         turn += 1
  225.         If turn > 2 Then
  226.             turn = 1
  227.         End If
  228.         Call win()
  229.         Button8.Enabled = False
  230.     End Sub
  231.  
  232.     Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
  233.         If turn = 1 Then
  234.             Button9.Text = "x"
  235.             Label2.Text = "o"
  236.         Else
  237.             Button9.Text = "o"
  238.             Label2.Text = "x"
  239.         End If
  240.         turn += 1
  241.         If turn > 2 Then
  242.             turn = 1
  243.         End If
  244.         Call win()
  245.         Button9.Enabled = False
  246.     End Sub
  247.  
  248.     Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
  249.         Button1.Text = ""
  250.         Button1.Enabled = True
  251.         Button2.Text = ""
  252.         Button2.Enabled = True
  253.         Button3.Text = ""
  254.         Button3.Enabled = True
  255.         Button4.Text = ""
  256.         Button4.Enabled = True
  257.         Button5.Text = ""
  258.         Button5.Enabled = True
  259.         Button6.Text = ""
  260.         Button6.Enabled = True
  261.         Button7.Text = ""
  262.         Button7.Enabled = True
  263.         Button8.Text = ""
  264.         Button8.Enabled = True
  265.         Button9.Text = ""
  266.         Button9.Enabled = True
  267.     End Sub
  268.  
  269.     Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
  270.         Button1.Text = ""
  271.         Button1.Enabled = True
  272.         Button2.Text = ""
  273.         Button2.Enabled = True
  274.         Button3.Text = ""
  275.         Button3.Enabled = True
  276.         Button4.Text = ""
  277.         Button4.Enabled = True
  278.         Button5.Text = ""
  279.         Button5.Enabled = True
  280.         Button6.Text = ""
  281.         Button6.Enabled = True
  282.         Button7.Text = ""
  283.         Button7.Enabled = True
  284.         Button8.Text = ""
  285.         Button8.Enabled = True
  286.         Button9.Text = ""
  287.         Button9.Enabled = True
  288.         Label5.Text = "0"
  289.         Label6.Text = "0"
  290.     End Sub
  291. End Class
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. Att: mchiappinam
Add Comment
Please, Sign In to add comment