CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2014
    Posts
    1

    Need help with poker hands code!

    Here is what I have so far
    Code:
     Public Class PokerHands
    
    Sub InputFormat() 'Function to remove space and change characters to UPPER CASE
            InputDisplay.Text = InputDisplay.Text.Replace(" ", "").Replace(",","").ToUpper
        End Sub
    
        Sub FourOfaKind() 'Four of a Kind
    
        End Sub
    
        Sub ThreeOfaKind() 'Three of a Kind
    
        End Sub
    
        Sub Pair() 'A pair
    
        End Sub
    
        Sub Flush() 'A flush
    
        End Sub
    
        Sub Straight() ' A straight, if ace is low
    
        End Sub
    
        Sub AceStraight() 'An ace-high straight; 10, J, Q, K, A
    
        End Sub
    
    
        Private Sub InputDisplay_TextChanged(ByVal sender As Object, e As EventArgs) Handles InputDisplay.TextChanged
    
    
    
        End Sub
    
        Private Sub Button1_Click(ByValsender As Object, e As EventArgs) Handles Button1.Click
            Dim hands(4, 13) As Integer 'Example: If (2,11) = 1 then is JD
            Dim SuitsValue() As String = {"S", "D", "C", "H"}
    
            Dim FaceValue() As String = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"}
        End Sub
    
    
    End Class
    Hi here is what I have my code so far. I am simply stuck as how to make the program reads the user input and then display the correpsonding deck. For example: if the user input "aH, AS, 2D, 3C, 4C" the program will return ace of hearts, ace of spades, two of diamonds, three of clubs, and four of clubs? Also how can the program will recognize that the first letter (substring (0,1) is the FaceValue and the second letter substring(1,1) is the SuitsValue? I understand I will need a loop function to determine all five. I am sorry if I am asking stupid questions here but I am really stuck!!!

    Thank you very much!

  2. #2
    Join Date
    Jul 2014
    Posts
    3

    Re: Need help with poker hands code!

    Maybe something like this will help get you started
    Code:
    Public Class Form1
        Private _PokerHands As PokerHands
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            _PokerHands = New PokerHands("AH, AS, 2D, 3C, 4C")
    
            Debug.Print(_PokerHands.Card1)
            Debug.Print(_PokerHands.Card2)
            Debug.Print(_PokerHands.Card3)
            Debug.Print(_PokerHands.Card4)
            Debug.Print(_PokerHands.Card5)
        End Sub
    End Class
    Code:
    Public Class PokerHands
        Public Property Card1 As String
        Public Property Card2 As String
        Public Property Card3 As String
        Public Property Card4 As String
        Public Property Card5 As String
    
        Public Sub New(cards As String)
            Dim hand() As String = cards.Split(New String() {", "}, StringSplitOptions.RemoveEmptyEntries)
    
            For Each playingCard As String In hand
    
                Select Case playingCard
    
                    Case "AH"
                        Card1 = "ace of hearts"
                    Case "AS"
                        Card2 = "ace of spades"
                    Case "2D"
                        Card3 = "two of diamonds"
                    Case "3C"
                        Card4 = "three of clubs"
                    Case "4C"
                        Card5 = "four of clubs"
    
                End Select
    
    
            Next
    
        End Sub
    
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured