Vache taureau

Description

Salut !
bref,
un jeu populaire Vache Taureau!
l'Ordi génère un nombre aléatoire et l'utilisateur de le trouvé !
Une simple application avec une jolie animation !
a vous de les découvrir.

Source / Exemple :


Option Explicit
Dim nombre As Long
Dim nombrech As String

Private Sub cmdaide_Click()
Form2.Show
End Sub

Private Sub cmdgo_Click()
'animation
Picture1.DrawWidth = 15
Picture2.DrawWidth = 15
Picture3.DrawWidth = 15
Dim x, y, color As Single
Dim i As Integer
For i = 1 To 15000
x = Picture1.ScaleWidth * Rnd
y = Picture1.ScaleHeight * Rnd
color = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
Picture1.PSet (x, y), color
x = Picture2.ScaleWidth * Rnd
y = Picture2.ScaleHeight * Rnd
color = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
Picture2.PSet (x, y), color
x = Picture3.ScaleWidth * Rnd
y = Picture3.ScaleHeight * Rnd
color = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
Picture3.PSet (x, y), color
DoEvents
Next
'traitement vt
If optfacile.Value = True Then
If IsNumeric(txttent.Text) And Len(txttent.Text) = 4 Then
Dim taur, vach As Integer
taur = 0: vach = 0
For i = 1 To 4
If Mid(txttent.Text, i, 1) = Mid(nombrech, i, 1) Then
taur = taur + 1
End If
Next i
Dim j As Integer
For i = 1 To 4
For j = 1 To 4
If Mid(txttent.Text, i, 1) = Mid(nombrech, j, 1) Then
vach = vach + 1
End If
Next
Next
vach = vach - taur
lsttent.AddItem (txttent.Text & " : " & taur & "T" & " & " & vach & "V")
txttent.Text = "": txttent.SetFocus
If taur = 4 Then
cmdpermuter.Visible = False
seelight
Label1.Visible = True
txttent.Visible = False
lblres.Caption = "the number is : " & nombrech
End If
Else
lblres = "nombre erroné"
End If
End If
If optmoyen.Value = True Then
If IsNumeric(txttent.Text) And Len(txttent.Text) = 5 Then
taur = 0: vach = 0
For i = 1 To 5
If Mid(txttent.Text, i, 1) = Mid(nombrech, i, 1) Then
taur = taur + 1
End If
Next i
For i = 1 To 5
For j = 1 To 5
If Mid(txttent.Text, i, 1) = Mid(nombrech, j, 1) Then
vach = vach + 1
End If
Next
Next
vach = vach - taur
lsttent.AddItem (txttent.Text & " : " & taur & "T" & " & " & vach & "V")
txttent.Text = "": txttent.SetFocus
If taur = 5 Then
cmdpermuter.Visible = False
seelight
Label1.Visible = True
txttent.Visible = False
lblres.Caption = "the number is : " & nombrech
End If
Else
lblres = "nombre erroné"
End If
End If
If optdifficile.Value = True Then
If IsNumeric(txttent.Text) And Len(txttent.Text) = 6 Then
taur = 0: vach = 0
For i = 1 To 6
If Mid(txttent.Text, i, 1) = Mid(nombrech, i, 1) Then
taur = taur + 1
End If
Next i
For i = 1 To 6
For j = 1 To 6
If Mid(txttent.Text, i, 1) = Mid(nombrech, j, 1) Then
vach = vach + 1
End If
Next
Next
vach = vach - taur
lsttent.AddItem (txttent.Text & " : " & taur & "T" & " & " & vach & "V")
txttent.Text = "": txttent.SetFocus
If taur = 6 Then
cmdpermuter.Visible = False
seelight
Label1.Visible = True
txttent.Visible = False
lblres.Caption = "the number is : " & nombrech
End If
Else
lblres = "nombre erroné"
End If
End If
End Sub
Private Sub seelight()
Timer1.Enabled = True
Shape1.FillColor = vbYellow
Shape2.FillColor = vbYellow
Shape1.FillStyle = 1
Timer1.Interval = 150
End Sub
Private Sub cmdinit_Click()
cmdpermuter.Visible = True
Label1.Visible = False
txttent.Visible = True
Timer1.Enabled = False
Shape1.FillStyle = 1
Shape2.FillStyle = 1
lsttent.Clear
txttent.Text = "": txttent.SetFocus
lblres.Caption = ""
Dim ok As Boolean
Dim i, j As Integer
If optfacile.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 9999) + 1
nombrech = nombre
For i = 1 To 3
For j = i + 1 To 4
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 4 And ok
Else
If optmoyen.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 99999) + 1
nombrech = nombre
For i = 1 To 4
For j = i + 1 To 5
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 5 And ok
Else
If optdifficile.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 999999) + 1
nombrech = nombre
For i = 1 To 5
For j = i + 1 To 6
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 6 And ok
End If
End If
End If
End Sub

Private Sub cmdloser_Click()
cmdpermuter.Visible = False
lblres.Caption = nombrech
Timer1.Enabled = True
Timer1.Interval = 150
Shape1.FillStyle = 1
Shape1.FillColor = vbRed
Shape2.FillColor = vbRed
End Sub

Private Sub cmdpermuter_Click()
If cmdpermuter.Caption = "}" Then
cmdpermuter.Caption = "{"
Form1.Width = Form1.Width + 5940
Else
cmdpermuter.Caption = "}"
Form1.Width = Form1.Width - 5940
End If
End Sub

Private Sub cmdquit_Click()
If MsgBox(" do you really want to exit this application ", vbYesNo, "attention") = vbYes Then
If MsgBox("hey you need to repeat the game !", vbYesNo, "ya m3allem brassommek win meshi") = vbNo Then
End
End If
End If
End Sub

Private Sub Form_Load()
cmdpermuter.Visible = True
Form1.Width = 6735
lsttent.Clear
Dim ok As Boolean
Dim i, j As Integer
If optfacile.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 9999) + 1
nombrech = nombre
For i = 1 To 3
For j = i + 1 To 4
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 4 And ok
Else
If optmoyen.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 99999) + 1
nombrech = nombre
For i = 1 To 4
For j = i + 1 To 5
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 5 And ok
Else
If optdifficile.Value = True Then
Do
ok = True
Randomize
nombre = (Rnd * 999999) + 1
nombrech = nombre
For i = 1 To 5
For j = i + 1 To 6
If Mid(nombrech, i, 1) = Mid(nombrech, j, 1) Then
ok = False
End If
Next
Next
Loop Until Len(nombrech) = 6 And ok
End If
End If
End If
End Sub

Private Sub Timer1_Timer()
If Shape1.FillStyle = 1 Then
Shape1.FillStyle = 0
Shape2.FillStyle = 1
Label1.Visible = False
Else
Shape1.FillStyle = 1
Shape2.FillStyle = 0
Label1.Visible = True
End If
End Sub
Private Sub txttent_GotFocus()
txttent.Text = ""
End Sub

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.