Results 1 to 9 of 9

Thread: hi lo card game

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    hi lo card game

    I have a couple quick questions with the program that I am doing. This program is a hi\lo program and here are my remaining issues...

    1. When I click the high or low button in my program it does not make changes to my token (I want the default tokens to be 100 and added 100 to the text property of my textbox so want to make sure I did that right)

    2. In my program it only shows 13 possibilities but want to have the ability to add more

    3. I also would like to change 1 to ace, 11 to jack, 12 to queen, and 13 to king and would like to get some assistance with that as well

    I think I have everything else taken care of but this is the code I have...

    Code:
    Public Class Form1
    
        Private randomgen As New Random
        Private cards As Integer
        Private cardpicked As Object
        Private clicked As Integer = 1
        Private used1, used2, used3, used4, used5, used6, used7, used8, used9, used10 As Integer
        Private myList As New List(Of Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For index As Integer = 1 To 13
    
                myList.Add(index)
    
            Next
    
            ShuffleCards(1000)
    
        End Sub
    
        Private Sub ShuffleCards(ByVal NumberOfTimes As Integer)
    
            Dim listIndex As Integer
            Dim output As String = ""
            Dim currentCard As Integer
    
            Try
    
                For index As Integer = 1 To NumberOfTimes
                    listIndex = randomgen.Next(1, 14) - 1
    
                    'Get a currentCard
                    currentCard = myList.Item(listIndex)
    
                    'Remove it at a RANDOM position.
                    myList.RemoveAt(listIndex)
    
                    'Add it back to the list at the end of the list.
                    myList.Add(currentCard)
    
                Next
    
                For cardNumber As Integer = 1 To 13
                    output &= myList(cardNumber - 1) & ControlChars.NewLine
    
                Next
    
            Catch
    
            End Try
    
            MessageBox.Show("Card Order is now" & ControlChars.NewLine & output)
    
        End Sub
    
        Private Sub PickCard()
    
            Dim cardNumber As Integer
            If myList.Count > 0 Then
    
                cardNumber = myList.Item(0)
                myList.RemoveAt(0)
    
            ElseIf myList.Count = 0 Then
    
                MessageBox.Show("No more cards left sorry!!")
    
                Exit Sub
    
            End If
    
            MessageBox.Show("CardNumber is now " & cardNumber)
    
            clicked = clicked + 1
    
        End Sub
    
    
    
        Private Sub cardCheckButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cardCheckButton.Click
    
            PickCard()
    
        End Sub
    
    
        Private Sub highButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles highButton.Click
            '  Dim cardNumber As Integer
            'If cardNumber >> cardpicked Then
            'tokensTextBox = 100 + 10
    
            'ElseIf cardNumber << cardpicked Then
            'tokensTextBox = 100 - 10
    
            'End If
    
        End Sub
    
        Private Sub tokensTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tokensTextBox.TextChanged
            'START WITH 100 TOKENS
    
        End Sub
    
        Private Sub lowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lowButton.Click
            'Dim cardNumber As Integer
            'If cardNumber >> cardpicked Then
            '   tokensTextBox = tokensTextBox - 10
    
            'ElseIf cardNumber << cardpicked Then
            '   tokensTextBox = 100 + 10
        End Sub
    
        Private Sub quitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quitButton.Click
            Me.Close()
        End Sub
    End Class

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: hi lo card game

    made some changes but still not working if anyone can take a look

    Code:
    Public Class Form1
    
        Private randomgen As New Random
        Private cards As Integer
        Private cardpicked As Object
        Private clicked As Integer = 1
        Private used1, used2, used3, used4, used5, used6, used7, used8, used9, used10 As Integer
        Private myList As New List(Of Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            For index As Integer = 1 To 13
    
                myList.Add(index)
    
            Next
    
            ShuffleCards(1000)
    
        End Sub
    
        Private Sub ShuffleCards(ByVal NumberOfTimes As Integer)
    
            Dim listIndex As Integer
            Dim output As String = ""
            Dim currentCard As Integer
    
            Try
    
                For index As Integer = 1 To NumberOfTimes
                    listIndex = randomgen.Next(1, 14) - 1
    
                    'Get a currentCard
                    currentCard = myList.Item(listIndex)
    
                    'Remove it at a RANDOM position.
                    myList.RemoveAt(listIndex)
    
                    'Add it back to the list at the end of the list.
                    myList.Add(currentCard)
    
                Next
    
                For cardNumber As Integer = 1 To 13
                    output &= myList(cardNumber - 1) & ControlChars.NewLine
    
                Next
    
            Catch
    
            End Try
    
            MessageBox.Show("Card Order is now" & ControlChars.NewLine & output)
    
        End Sub
    
        Private Sub PickCard()
    
            Dim cardNumber As Integer
            If myList.Count > 0 Then
    
                cardNumber = myList.Item(0)
                myList.RemoveAt(0)
    
            ElseIf myList.Count = 0 Then
    
                MessageBox.Show("No more cards left sorry!!")
    
                Exit Sub
    
            End If
    
            'BEFORE OPENING THE PROGRAM THIS SHOWS THE ORDER OF THE CARDS
            MessageBox.Show("CardNumber is now " & cardNumber)
    
            clicked = clicked + 1
    
        End Sub
    
    
    
        Private Sub cardCheckButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cardCheckButton.Click
    
            PickCard()
    
        End Sub
    
    
        Private Sub highButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles highButton.Click
            Dim cardNumber As Integer
            If cardNumber > cardpicked Then
                tokensTextBox.Text = tokensTextBox.Text + tokensToBetTextBox.Text
    
            ElseIf cardNumber < cardpicked Then
                tokensTextBox.Text = tokensTextBox.Text - tokensToBetTextBox.Text
    
            End If
    
        End Sub
    
        Private Sub tokensTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tokensTextBox.TextChanged
            'START WITH 100 TOKENS
    
        End Sub
    
        Private Sub lowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lowButton.Click
            Dim cardNumber As Integer
            If cardNumber > cardpicked Then
                tokensTextBox.Text = tokensTextBox.Text - tokensToBetTextBox.Text
    
            ElseIf cardNumber < cardpicked Then
                tokensTextBox.Text = tokensTextBox.Text + tokensToBetTextBox.Text
    
            End If
        End Sub
    
        Private Sub quitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles quitButton.Click
            Me.Close()
        End Sub
    
        Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
            Me.Close()
        End Sub
    
        Private Sub tokensToBetTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tokensToBetTextBox.TextChanged
            If Val(tokensToBetTextBox.Text) < 10 Then
                tokensToBetTextBox.Text = Val(tokensToBetTextBox.Text)
            End If
        End Sub
    End Class

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: hi lo card game

    What are the rules of Hi / Lo ? How do you play?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: hi lo card game

    here are the instructions(I do not need images of the cards)

    Higher or lower is played by shuffling the cards, and then dealing one card from the deck. The player then chooses whether the next card drawn from the deck
    will be higher or lower than the first card drawn. It the player guesses correctly, they win. Otherwise they lose.
    Your game should have the facilities to keep score in some manner – tokens tend to work well.
    You should add embellishments to your program to make it attractive to potential players.
    One decision you must make is when to deal the cards. The odds change based upon whether you deal prior to each game, or if you use the same deck for several hands of the game.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: hi lo card game

    here are the instructions(I do not need images of the cards)

    Higher or lower is played by shuffling the cards, and then dealing one card from the deck. The player then chooses whether the next card drawn from the deck
    will be higher or lower than the first card drawn. It the player guesses correctly, they win. Otherwise they lose.
    Your game should have the facilities to keep score in some manner – tokens tend to work well.
    You should add embellishments to your program to make it attractive to potential players.
    One decision you must make is when to deal the cards. The odds change based upon whether you deal prior to each game, or if you use the same deck for several hands of the game.
    bkruep is online now Rate this post
    Add to bkruep's Reputation Report Post Edit/Delete Message

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: hi lo card game

    Card ideas

    Code:
        Class tCard
            Public _rank As Ranks
            Public _suit As Suits
        End Class
    
        Dim deck As List(Of tCard)
        Dim PRNG As New Random
    
        Private Sub Button2_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button2.Click
            'shuffle new deck
    
            deck = New List(Of tCard)
            For Each s As Suits In [Enum].GetValues(GetType(Suits))
                For Each r As Ranks In [Enum].GetValues(GetType(Ranks))
                    Dim foo As New tCard
                    foo._rank = r
                    foo._suit = s
                    deck.Add(foo)
                Next
            Next
            deck = deck.OrderBy(Function(rn) PRNG.Next).ToList
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles Button3.Click
    
            Dim c1 As tCard = GetCardFromDeck()
            Dim c2 As tCard = GetCardFromDeck()
            If c1._rank > c2._rank Then
                Stop
            ElseIf c1._rank < c2._rank Then
                Stop
            Else
                Stop
            End If
        End Sub
    
        Function GetCardFromDeck() As tCard
            If deck.Count = 0 Then
                'no more cards
                Throw New IndexOutOfRangeException("Deck Empty")
            End If
            Dim idx As Integer = PRNG.Next(deck.Count)
            Dim aCard As New tCard
            aCard = deck(idx)
            deck.RemoveAt(idx)
            Return aCard
        End Function
    
    
    
    Public Enum Suits
        Spades
        Hearts
        Diamonds
        Clubs
    End Enum
    
    Public Enum Ranks
        Two
        Three
        Four
        Five
        Six
        Seven
        Eight
        Nine
        Ten
        Jack
        Queen
        King
        Ace
    End Enum
    
    Public Structure deckConstants
        Shared NumberOfSuits As Integer = [Enum].GetNames(GetType(Suits)).Length
        Shared NumberOfRanks As Integer = [Enum].GetNames(GetType(Ranks)).Length
    End Structure
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: hi lo card game

    So are you suggesting I disregard my entire code and use all the changes you made from the code you just posted(fyi that response did not mean any disrespect but over a forum and not face to face it may sound like it but thank you for your help)

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: hi lo card game

    I was just showing you a slightly different approach. You seem to have the basics down. If you disregard what I posted it will not bother me in the least. You won't be the first, you won't be the last.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    25

    Re: hi lo card game

    haha sounds good Ill plug in your code when I get home tonight and take a look. I do not see form1 but I am guessing it all goes in there

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