JOGINHO NO VB

AUGUSTTO 25/05/2005 19:21:06
#85237
estou fazendo um jogo da velha no VB,eu consegui fazer jogando de 2 pessoas mas eu queria também fazer jogar contra o computador,eu não tenho nem noção de como se começa e também o codigo não muito complicado,alguém pode me ajudar?

desde já eu agradeço
FIREONBOMB 25/05/2005 19:43:43
#85241
uai, manda aí q nóis vê
AUGUSTTO 25/05/2005 19:57:59
#85243
como eu posso mandar
FIREONBOMB 25/05/2005 20:31:19
#85249
as linhas de codigo
AUGUSTTO 25/05/2005 21:23:21
#85258
foi assim que eu criei:
1 label,criei um array de 9 posição e o nome lbljogo
2 command button,cmd inicio e cmd limpar
2 textbox para a pontuação,txtX e txtO
2 optionbutton para escolher as marcas caption X e no outro O

codigo:

Dim marca As String
Dim XO(0 To 8) As String
Private Sub cmdinicio_Click()
optO.Value = False
optX.Value = False
optO.Enabled = True
optX.Enabled = True
marca = ""
Dim i
For i = 0 To 8
XO(i) = ""
lbljogo(i).Caption = ""
lbljogo(i).Enabled = True
Next
End Sub


Private Sub cmdlimpar_Click()
txtX.Text = ""
txtO.Text = ""
End Sub

Private Sub Form_Load()
optO.Value = False
optX.Value = False
optO.Enabled = False
optX.Enabled = False
marca = ""
txtX.Locked = True
txtO.Locked = True
Dim i
For i = 0 To 8
lbljogo(i).Caption = " "
lbljogo(i).Enabled = False
Next
End Sub
Private Sub lbljogo_Click(Index As Integer)
If optX.Value = True Or optO.Value = True Then
If lbljogo(Index).Caption = "" Then
lbljogo(Index).Caption = marca
vencedor marca, Index
outra_marca (marca)
Else
MsgBox "Escolha outro lugar", vbInformation, "Atenção !"
End If
Else
MsgBox "Escolha uma marca para jogar", vbInformation, "Atenção !"
End If
End Sub

Private Sub optO_Click()
If optO.Value = True Then
marca = "O"
End If
End Sub

Private Sub optX_Click()
If optX.Value = True Then
marca = "X"

End If
End Sub

Private Sub outra_marca(M As String)
If M = "X" Then
marca = "O"
Else
marca = "X"
End If
End Sub

Private Sub vencedor(M As String, i As Integer)
If lbljogo(i).Caption <> "" Then
XO(i) = lbljogo(i).Caption
End If
If XO(0) = M And XO(0) = XO(1) And XO(1) = XO(2) Then 'Verifica se existe ganhador
If M = "X" Then 'nas linhas,se existir soma +1 na pontuação
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
ElseIf XO(3) = M And XO(3) = XO(4) And XO(4) = XO(5) Then
If M = "X" Then
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
ElseIf XO(6) = M And XO(6) = XO(7) And XO(7) = XO(8) Then
If M = "X" Then
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
'------------------------------------------------------------
ElseIf XO(0) = M And XO(0) = XO(4) And XO(4) = XO(8) Then 'Verifica se existe ganhador
If M = "X" Then 'nas diagonais,se existir soma +1 na pontuação
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
ElseIf XO(2) = M And XO(2) = XO(4) And XO(4) = XO(6) Then
If M = "X" Then
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
'--------------------------------------------------------------
ElseIf XO(0) = M And XO(0) = XO(3) And XO(3) = XO(6) Then 'Verifica se existe ganhador
If M = "X" Then 'nas colunas,se existir soma +1 na pontuação
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
ElseIf XO(1) = M And XO(1) = XO(4) And XO(4) = XO(7) Then
If M = "X" Then
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
ElseIf XO(2) = M And XO(2) = XO(5) And XO(5) = XO(8) Then
If M = "X" Then
txtX.Text = Val(txtX.Text) + Val(1)
Else
txtO.Text = Val(txtO.Text) + Val(1)
End If
MsgBox "Ganhou o : " & M, vbInformation, "Ganhador"
For i = 0 To 8
lbljogo(i).Enabled = False
Next
End If
End Sub

este codigo jogo-se de 2 pessoas,o que eu não sei e queria saber é fazer contra o computador
GABRIEL.LOGAN 25/05/2005 21:28:01
#85260
Resposta escolhida
Cara, você vai ter que fazer Scripts ou então formular uma A.I (Inteligência Artificial) isso vai dar um código enorme.....

Boa sorte e muita paciência!
Tópico encerrado , respostas não são mais permitidas