Option Strict On
Public Class frmCards
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblHand As System.Windows.Forms.Label
Friend WithEvents btnDeal As System.Windows.Forms.Button
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents btnClear As System.Windows.Forms.Button
Friend WithEvents lblResult As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblHand = New System.Windows.Forms.Label
Me.btnDeal = New System.Windows.Forms.Button
Me.btnExit = New System.Windows.Forms.Button
Me.btnClear = New System.Windows.Forms.Button
Me.lblResult = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'lblHand
'
Me.lblHand.Location = New System.Drawing.Point(24, 24)
Me.lblHand.Name = "lblHand"
Me.lblHand.Size = New System.Drawing.Size(160, 152)
Me.lblHand.TabIndex = 0
'
'btnDeal
'
Me.btnDeal.Location = New System.Drawing.Point(200, 24)
Me.btnDeal.Name = "btnDeal"
Me.btnDeal.TabIndex = 5
Me.btnDeal.Text = "Deal"
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(200, 240)
Me.btnExit.Name = "btnExit"
Me.btnExit.TabIndex = 6
Me.btnExit.Text = "Exit"
'
'btnClear
'
Me.btnClear.Location = New System.Drawing.Point(200, 64)
Me.btnClear.Name = "btnClear"
Me.btnClear.TabIndex = 7
Me.btnClear.Text = "Clear"
'
'lblResult
'
Me.lblResult.Location = New System.Drawing.Point(24, 240)
Me.lblResult.Name = "lblResult"
Me.lblResult.Size = New System.Drawing.Size(160, 23)
Me.lblResult.TabIndex = 8
Me.lblResult.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'frmCards
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 278)
Me.Controls.Add(Me.lblResult)
Me.Controls.Add(Me.btnClear)
Me.Controls.Add(Me.btnExit)
Me.Controls.Add(Me.btnDeal)
Me.Controls.Add(Me.lblHand)
Me.Name = "frmCards"
Me.Text = "Card Dealer"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnDeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeal.Click
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 As Integer() = New Integer(51) {}
Dim myHand As String() = New String(5) {}
Dim myHandPairs As Integer() = New Integer(3) {}
For intX = 1 To 5
Do
intCardNum = rndNum.Next(0, 52)
Loop Until Deck(intCardNum) = 0
Deck(intCardNum) = 1
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)
If (intHandIndex = 6) Then
intHandIndex = 5
End If
lblResult.Text = HandStrength(intHandIndex)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lblHand.Text = ""
lblResult.Text = ""
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Close()
End Sub
End Class