I have decided to create Bulls and Cows game for my project. I have been checking for it's correctness. But it behaves bad in some cases. Like when I have already guessed the word it doesn't respond right. This happened rarely but I can conclude that it still is not right.I get words from a notepad file randomly.
Can anyone tell me why it behaves erratic.
some initializations
dim str as string
str = TextBox1.Text
str2 = str.ToCharArray()
Dim str3(100) As Char
Dim str4(100) As Char
Public Sub checkbulls(ByVal guess1 As String)
Try
'Throw (New MyException("please select a choice"))
guess = guess1
Dim i As Integer
For i = 0 To 3
str3(i) = str2(i)
str4(i) = guess.Chars(i)
If (str3(i) = str4(i)) Then
bulls = bulls + 1
str3(i) = "#"
str4(i) = "!"
End If
Next
ListBox2.Items.Add(bulls)
'won()
bulls = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub checkcows()
Try
Dim i As Integer
Dim j As Integer
For i = 0 To 3
For j = 0 To 3
If (str3(i) = str4(j)) Then
cows = cows + 1
str3(i) = "#"
str4(j) = "!"
End If
Next
Next
ListBox3.Items.Add(cows)
cows = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub