Private Sub btnDeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeal.Click
Me.lblHand.Text = ""
Dim rndNum As Random = New Random()
Dim intX, intY As Integer
Dim intCardNum As Integer
Dim intSuitNum As Integer
Dim intFaceNum As Integer
Dim intHandIndex As Integer = 0
Dim Suits As String() = New String() {"Hearts", "Diamonds", _
"Clubs", "Spades"}
Dim Faces As String() = New String() {"Ace", "Deuce", "Three", _
"Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", _
"Jack", "Queen", "King"}
Dim HandStrength As String() = New String() {"Nothing Special", "There is a pair", _
"There are two pairs", "There is three of a kind", "There is a full house", _
"There is four of a kind"}
Dim Deck(51) As Integer
Dim myHand(4) As String
Dim myHandPairs(3) As Integer
'For intX = 1 To 5
' Do
' intCardNum = rndNum.Next(0, 52)
' Loop Until Deck(intCardNum) = 0
' Deck(intCardNum) = 1
'Next
'fill
For nValue As Integer = 0 To Deck.Length - 1
Deck(nValue) = nValue + 1
Next
'mix
For nLoop As Integer = 1 To 1000
Dim nLeft As Integer = rndNum.Next(0, Deck.Length - 1)
Dim nRight As Integer = rndNum.Next(0, Deck.Length - 1)
Dim nSwap As Integer = Deck(nLeft)
Deck(nLeft) = Deck(nRight)
Deck(nRight) = nSwap
Next
'deal hand
For nLoop As Integer = 0 To myHand.Length - 1
myHand(nLoop) = Faces((Deck(nLoop) \ 13)) + " of " + Suits(CType(Math.Floor(Deck(nLoop) / 13), Integer))
Next
'show hand
For nCard As Integer = 0 To myHand.Length - 1
Me.lblHand.Text += myHand(nCard) + ControlChars.CrLf
Next
'lblHand.Text = ""
'For intX = 0 To 51
' If Deck(intX) = 1 Then
' intSuitNum = intX \ 13
' intFaceNum = intX - (intSuitNum * 13) 'or intX mod 13
' lblHand.Text = lblHand.Text + Faces(intFaceNum) + _
' " Of " + Suits(intSuitNum) + vbCrLf + vbCrLf
' myHand(intHandIndex) = Convert.ToString(intFaceNum)
' intHandIndex += 1
' End If
'Next
Dim pair As Integer = 0
' For testing :)
'myHand = New String() {"Ace", "Three", "Ace", "Ace", "Ace"}
While pair < 3
For intY = 0 To 4
For intX = intY + 1 To 4
If (myHand(intY) = myHand(intX)) Then
' Finds the ammount of times that intY is found and
' adds to value in myHandsPairs(pair)
myHandPairs(pair) = myHandPairs(pair) + 1
End If
Next
pair += 1
Next
End While
intHandIndex = myHandPairs(0) + myHandPairs(1) + myHandPairs(2) + myHandPairs(3)
'Problem occurs in the lblResult.text below. If intHandIndex isn't reset to 5, there is an out of bounds error.
' I`m not sure how to fix this so that intHandIndex will never be
If (intHandIndex = 6) Then
intHandIndex = 5
End If
lblResult.Text = HandStrength(intHandIndex)
End Sub