bulfaitelo

jogo da velha

Mar 29th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Verifica As Boolean
  2. Public Cont, X, Y As Byte
  3. Public Ganhador, Ganhador1 As String
  4.  
  5. Private Sub BtnIniciar_Click()
  6.     AtivaBotoes
  7.     LimpaMesa
  8.     Cont = 0
  9.         Label1.Caption = "Começa jogando o nome que tem o " & Ganhador1
  10.        
  11. End Sub
  12.  
  13. Private Sub Form_load()
  14.     LblPrimeiro.Caption = primeiro
  15.     LblSegundo.Caption = segundo
  16.     Verifica = True
  17.     Cont = 0
  18. End Sub
  19.  
  20. Private Sub mesa0_Click()
  21.     If Verifica = True Then
  22.         mesa0.Caption = "x"
  23.         Verifica = False
  24.         mesa0.Enabled = False
  25.         X = X + 1
  26.     Else
  27.         mesa0.Caption = "0"
  28.         Verifica = True
  29.         mesa0.Enabled = False
  30.         Y = Y + 1
  31.     End If
  32.         Cont = Cont + 1
  33.         verificaGanhador
  34. End Sub
  35.  
  36. Private Sub Mesa1_Click()
  37.     If Verifica = True Then
  38.         mesa1.Caption = "X"
  39.         Verifica = False
  40.         mesa1.Enabled = False
  41.         X = X + 1
  42.     Else
  43.         mesa1.Caption = "0"
  44.         Verifica = True
  45.         mesa1.Enabled = False
  46.         Y = Y + 1
  47.     End If
  48.         Cont = Cont + 1
  49.         verificaGanhador
  50. End Sub
  51.  
  52. Private Sub Mesa2_Click()
  53.     If Verifica = True Then
  54.         mesa2.Caption = "X"
  55.         Verifica = False
  56.         mesa2.Enabled = False
  57.         X = X + 1
  58.     Else
  59.         mesa2.Caption = "0"
  60.         Verifica = True
  61.         mesa2.Enabled = False
  62.         Y = Y + 1
  63.     End If
  64.         Cont = Cont + 1
  65.         verificaGanhador
  66. End Sub
  67.  
  68. Private Sub Mesa3_Click()
  69.     If Verifica = True Then
  70.         mesa3.Caption = "X"
  71.         Verifica = False
  72.         mesa3.Enabled = False
  73.         X = X + 1
  74.     Else
  75.         mesa3.Caption = "0"
  76.         Verifica = True
  77.         mesa3.Enabled = False
  78.         Y = Y + 1
  79.     End If
  80.         Cont = Cont + 1
  81.         verificaGanhador
  82. End Sub
  83.  
  84.  
  85. Private Sub Mesa4_Click()
  86.     If Verifica = True Then
  87.         mesa.Caption = "X"
  88.         Verifica = False
  89.         mesa4.Enabled = False
  90.         X = X + 1
  91.     Else
  92.         mesa4.Caption = "0"
  93.         Verifica = True
  94.         mesa4.Enabled = False
  95.         Y = Y + 1
  96.     End If
  97.         Cont = Cont + 1
  98.         verificaGanhador
  99. End Sub
  100.  
  101. Private Sub Mesa5_Click()
  102.     If Verifica = True Then
  103.         mesa5.Caption = "X"
  104.         Verifica = False
  105.         mesa5.Enabled = False
  106.         X = X + 1
  107.     Else
  108.         mesa5.Caption = "0"
  109.         Verifica = True
  110.         mesa5.Enabled = False
  111.         Y = Y + 1
  112.     End If
  113.         Cont = Cont + 1
  114.         verificaGanhador
  115. End Sub
  116.  
  117. Private Sub Mesa6_Click()
  118.     If Verifica = True Then
  119.         mesa6.Caption = "X"
  120.         Verifica = False
  121.         mesa6.Enabled = False
  122.         X = X + 1
  123.     Else
  124.         mesa6.Caption = "0"
  125.         Verifica = True
  126.         mesa6.Enabled = False
  127.         Y = Y + 1
  128.     End If
  129.         Cont = Cont + 1
  130.         verificaGanhador
  131. End Sub
  132.  
  133. Private Sub Mesa7_Click()
  134.     If Verifica = True Then
  135.         mesa7.Caption = "X"
  136.         Verifica = False
  137.         mesa7.Enabled = False
  138.         X = X + 1
  139.     Else
  140.         mesa7.Caption = "0"
  141.         Verifica = True
  142.         mesa7.Enabled = False
  143.         Y = Y + 1
  144.     End If
  145.         Cont = Cont + 1
  146.         verificaGanhador
  147. End Sub
  148.  
  149. Private Sub Mesa8_Click()
  150.     If Verifica = True Then
  151.         mesa8.Caption = "X"
  152.         Verifica = False
  153.         mesa8.Enabled = False
  154.         X = X + 1
  155.     Else
  156.         mesa8.Caption = "0"
  157.         Verifica = True
  158.         mesa8.Enabled = False
  159.         Y = Y + 1
  160.     End If
  161.         Cont = Cont + 1
  162.         verificaGanhador
  163. End Sub
  164.  
  165. Private Sub verificaGanhador()
  166.     If (mesa0.Caption = "x" And mesa1.Caption = "x" And mesa2.Caption = "x") Or (mesa0.Caption = "0" And mesa1.Caption = "0" And mesa2.Caption = "0") Then
  167.         QuemGanhou
  168.         MsgBox "O Ganhador foi: " & Ganhador
  169.         DesativaBotoes
  170.         Somaponto
  171.         Exit Sub
  172.    
  173.     ElseIf (mesa3.Caption = "x" And mesa4.Caption = "x" And mesa5.Caption = "x") Or (mesa3.Caption = "0" And mesa4.Caption = "0" And mesa5.Caption = "0") Then
  174.         QuemGanhou
  175.         MsgBox "O Ganhador foi: " & Ganhador
  176.         DesativaBotoes
  177.         Somaponto
  178.         Exit Sub
  179.     ElseIf (mesa6.Caption = "x" And mesa7.Caption = "x" And mesa8.Caption = "x") Or (mesa6.Caption = "0" And mesa7.Caption = "0" And mesa8.Caption = "0") Then
  180.         QuemGanhou
  181.         MsgBox "O Ganhador foi: " & Ganhador
  182.         DesativaBotoes
  183.         Somaponto
  184.         Exit Sub
  185.     ElseIf (mesa0.Caption = "x" And mesa3.Caption = "x" And mesa6.Caption = "x") Or (mesa0.Caption = "0" And mesa3.Caption = "0" And mesa6.Caption = "0") Then
  186.         QuemGanhou
  187.         MsgBox "O Ganhador foi: " & Ganhador
  188.         DesativaBotoes
  189.         Somaponto
  190.         Exit Sub
  191.     ElseIf (mesa1.Caption = "x" And mesa4.Caption = "x" And mesa7.Caption = "x") Or (mesa1.Caption = "0" And mesa4.Caption = "0" And mesa7.Caption = "0") Then
  192.         QuemGanhou
  193.         MsgBox "O Ganhador foi: " & Ganhador
  194.         DesativaBotoes
  195.         Somaponto
  196.         Exit Sub
  197.     ElseIf (mesa2.Caption = "x" And mesa5.Caption = "x" And mesa8.Caption = "x") Or (mesa2.Caption = "0" And mesa5.Caption = "0" And mesa8.Caption = "0") Then
  198.         QuemGanhou
  199.         MsgBox "O Ganhador foi: " & Ganhador
  200.         DesativaBotoes
  201.         Somaponto
  202.         Exit Sub
  203.     ElseIf (mesa0.Caption = "x" And mesa4.Caption = "x" And mesa8.Caption = "x") Or (mesa0.Caption = "0" And mesa4.Caption = "0" And mesa8.Caption = "0") Then
  204.         QuemGanhou
  205.         MsgBox "O Ganhador foi: " & Ganhador
  206.         DesativaBotoes
  207.         Somaponto
  208.         Exit Sub
  209.     ElseIf (mesa2.Caption = "x" And mesa4.Caption = "x" And mesa6.Caption = "x") Or (mesa2.Caption = "0" And mesa4.Caption = "0" And mesa6.Caption = "0") Then
  210.         QuemGanhou
  211.         MsgBox "O Ganhador foi: " & Ganhador
  212.         DesativaBotoes
  213.         Somaponto
  214.         Exit Sub
  215.     End If
  216.     If Cont = 9 Then
  217.         MsgBox "Não ouve ganhador", Vblnformation, "Jogo da Velha"
  218.             Ganhador1 = "0"
  219.             Verifica = False
  220.         End If
  221.     End Sub
  222. Private Sub mnujogosair_Click()
  223.     End
  224. End Sub
  225. Private Sub DesativaBotoes()
  226.     mesa0.Enabled = False
  227.     mesa1.Enabled = False
  228.     mesa2.Enabled = False
  229.     mesa3.Enabled = False
  230.     mesa4.Enabled = False
  231.     mesa5.Enabled = False
  232.     mesa6.Enabled = False
  233.     mesa7.Enabled = False
  234.     mesa8.Enabled = False
  235.    
  236. End Sub
  237. Private Sub AtivaBotoes()
  238.     mesa0.Enabled = True
  239.     mesa1.Enabled = True
  240.     mesa2.Enabled = True
  241.     mesa3.Enabled = True
  242.     mesa4.Enabled = True
  243.     mesa5.Enabled = True
  244.     mesa6.Enabled = True
  245.     mesa7.Enabled = True
  246.     mesa8.Enabled = True
  247. End Sub
  248. Private Sub QuemGanhou()
  249.     If X > Y Then
  250.         Ganhador = "x"
  251.         Ganhador1 = "0"
  252.     Else
  253.         Ganhador = "x"
  254.         Ganhador1 = "0"
  255.     End If
  256. End Sub
  257. Private Sub Somaponto()
  258.     If X > Y Then
  259.         LblPlacarPrimeiro.Caption = Val(LblPlacarPrimeiro.Caption) + 1
  260.     Else
  261.         LblPlacarSegundo.Caption = Val(LblPlacarSegundo.Caption) + 1
  262.     End If
  263. End Sub
  264. Private Sub LimpaMesa()
  265.     mesa0.Enabled = ""
  266.     mesa1.Enabled = ""
  267.     mesa2.Enabled = ""
  268.     mesa3.Enabled = ""
  269.     mesa4.Enabled = ""
  270.     mesa5.Enabled = ""
  271.     mesa6.Enabled = ""
  272.     mesa7.Enabled = ""
  273.     mesa8.Enabled = ""
  274. End Sub
Advertisement
Add Comment
Please, Sign In to add comment