Welcome to Dream.In.Code
Become a VB Expert!

Join 137,228 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




Blackjack Application

 
Reply to this topicStart new topic

Blackjack Application

orangeslide8
3 Feb, 2007 - 11:03 AM
Post #1

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
ok so i wrote the code and everything works exept it tells me ive busted when i havn't and sometimes doesn't tell me ive busted when i have. O and this isn't the full code its just the part up to busting. Thnx
john
CODE

Public Class Form1
    Dim Cards(4, 13)
    Dim CardsUsed(4, 13)
    Dim X = 0
    Dim Y = 0
    Dim MyCards(26)
    Dim AICards(26)
    Dim Z As Integer
    Dim W As Integer
    Dim AINumbers(26)
    Dim MyNumbers(26)
    Dim Bet As Integer
    Dim Visiblecard As Boolean
    Dim Ace1 As Boolean
    Dim Ace2 As Boolean
    Dim Ace3 As Boolean
    Dim Ace4 As Boolean
    Dim Ace5 As Boolean
    Dim WhichCard As Integer
    Dim Numberofcards As Integer
    Private Sub AssignmyCards()
        Label1.Text = MyCards(1)
        Label2.Text = MyCards(2)
        Label3.Text = MyCards(3)
        Label4.Text = MyCards(4)
        Label5.Text = MyCards(5)
        Label6.Text = MyCards(6)
        Label7.Text = MyCards(7)
        Label8.Text = MyCards(8)
    End Sub
    Private Sub AssignAICards()
        Label9.Text = AICards(1)
        Label10.Text = AICards(2)
        Label11.Text = AICards(3)
        Label12.Text = AICards(4)
        Label13.Text = AICards(5)
        Label14.Text = AICards(6)
        Label15.Text = AICards(7)
        Label16.Text = AICards(8)
    End Sub
    Private Sub SetCards()
        Cards(1, 1) = ("Ace Of Dimonds")
        Cards(1, 2) = ("Two Of Dimonds")
        Cards(1, 3) = ("Three Of Dimonds")
        Cards(1, 4) = ("Four Of Dimonds")
        Cards(1, 5) = ("Five Of Dimonds")
        Cards(1, 6) = ("Six Of Dimonds")
        Cards(1, 7) = ("Seven Of Dimonds")
        Cards(1, 8) = ("Eight Of Dimonds")
        Cards(1, 9) = ("Nine Of Dimonds")
        Cards(1, 10) = ("Ten Of Dimonds")
        Cards(1, 11) = ("Jack Of Dimonds")
        Cards(1, 12) = ("Queen Of Dimonds")
        Cards(1, 13) = ("King Of Dimonds")

        Cards(2, 1) = ("Ace Of Spades")
        Cards(2, 2) = ("Two Of Spades")
        Cards(2, 3) = ("Three Of Spades")
        Cards(2, 4) = ("Four Of Spades")
        Cards(2, 5) = ("Five Of Spades")
        Cards(2, 6) = ("Six Of Spades")
        Cards(2, 7) = ("Seven Of Spades")
        Cards(2, 8) = ("Eight Of Spades")
        Cards(2, 9) = ("Nine Of Spades")
        Cards(2, 10) = ("Ten Of Spades")
        Cards(2, 11) = ("Jack Of Spades")
        Cards(2, 12) = ("Queen Of Spades")
        Cards(2, 13) = ("King Of Spades")

        Cards(3, 1) = ("Ace Of Clubs")
        Cards(3, 2) = ("Two Of Clubs")
        Cards(3, 3) = ("Three Of Clubs")
        Cards(3, 4) = ("Four Of Clubs")
        Cards(3, 5) = ("Five Of Clubs")
        Cards(3, 6) = ("Six Of Clubs")
        Cards(3, 7) = ("Seven Of Clubs")
        Cards(3, 8) = ("Eight Of Clubs")
        Cards(3, 9) = ("Nine Of Clubs")
        Cards(3, 10) = ("Ten Of Clubs")
        Cards(3, 11) = ("Jack Of Clubs")
        Cards(3, 12) = ("Queen Of Clubs")
        Cards(3, 13) = ("King Of Clubs")

        Cards(4, 1) = ("Ace Of Hearts")
        Cards(4, 2) = ("Two Of Hearts")
        Cards(4, 3) = ("Three Of Hearts")
        Cards(4, 4) = ("Four Of Hearts")
        Cards(4, 5) = ("Five Of Hearts")
        Cards(4, 6) = ("Six Of Hearts")
        Cards(4, 7) = ("Seven Of Hearts")
        Cards(4, 8) = ("Eight Of Hearts")
        Cards(4, 9) = ("Nine Of Hearts")
        Cards(4, 10) = ("Ten Of Hearts")
        Cards(4, 11) = ("Jack Of Hearts")
        Cards(4, 12) = ("Queen Of Hearts")
        Cards(4, 13) = ("King Of Hearts")
    End Sub
    Private Sub SetCardsused()
        CardsUsed(1, 1) = False
        CardsUsed(1, 2) = False
        CardsUsed(1, 3) = False
        CardsUsed(1, 4) = False
        CardsUsed(1, 5) = False
        CardsUsed(1, 6) = False
        CardsUsed(1, 7) = False
        CardsUsed(1, 8) = False
        CardsUsed(1, 9) = False
        CardsUsed(1, 10) = False
        CardsUsed(1, 11) = False
        CardsUsed(1, 12) = False
        CardsUsed(1, 13) = False

        CardsUsed(2, 1) = False
        CardsUsed(2, 2) = False
        CardsUsed(2, 3) = False
        CardsUsed(2, 4) = False
        CardsUsed(2, 5) = False
        CardsUsed(2, 6) = False
        CardsUsed(2, 7) = False
        CardsUsed(2, 8) = False
        CardsUsed(2, 9) = False
        CardsUsed(2, 10) = False
        CardsUsed(2, 11) = False
        CardsUsed(2, 12) = False
        CardsUsed(2, 13) = False

        CardsUsed(3, 1) = False
        CardsUsed(3, 2) = False
        CardsUsed(3, 3) = False
        CardsUsed(3, 4) = False
        CardsUsed(3, 5) = False
        CardsUsed(3, 6) = False
        CardsUsed(3, 7) = False
        CardsUsed(3, 8) = False
        CardsUsed(3, 9) = False
        CardsUsed(3, 10) = False
        CardsUsed(3, 11) = False
        CardsUsed(3, 12) = False
        CardsUsed(3, 13) = False

        CardsUsed(4, 1) = False
        CardsUsed(4, 2) = False
        CardsUsed(4, 3) = False
        CardsUsed(4, 4) = False
        CardsUsed(4, 5) = False
        CardsUsed(4, 6) = False
        CardsUsed(4, 7) = False
        CardsUsed(4, 8) = False
        CardsUsed(4, 9) = False
        CardsUsed(4, 10) = False
        CardsUsed(4, 11) = False
        CardsUsed(4, 12) = False
        CardsUsed(4, 13) = False
    End Sub
    Private Sub Dealme1card()
        X = X + 1
Top:    Randomize()
        Z = Int(Rnd() * 12) + 1
        W = Int(Rnd() * 3) + 1
        If CardsUsed(W, Z) = True Then
            GoTo Top
        End If
        MyCards(X) = Cards(W, Z)
        CardsUsed(W, Z) = True
        If Z > 10 Then
            Z = 10
        End If
        MyNumbers(X) = Z
        AssignmyCards()
    End Sub
    Private Sub DealAI1Card()
        Y = Y + 1
Top:    Randomize()
        Z = Int(Rnd() * 12) + 1
        W = Int(Rnd() * 3) + 1
        If CardsUsed(W, Z) = True Then
            GoTo Top
        End If
        AICards(Y) = Cards(W, Z)
        CardsUsed(W, Z) = True
        If Z > 10 Then
            Z = 10
        End If
        AINumbers(Y) = Z
        If Visiblecard = False Then
            GoTo Bottom
        End If
        AssignAICards()
Bottom:
    End Sub
    Private Sub betting()
        Panel1.Visible = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SetCards()
        SetCardsused()
        Dealme1card()
        Dealme1card()
        DealAI1Card()
        DealAI1Card()
        Button1.Visible = False
        betting()
    End Sub
    Private Sub AIBetting1()
        If AINumbers(1) = 1 Then
            Ace1 = True
        End If
        If AINumbers(2) = 1 Then
            Ace2 = True
        End If
        If Ace1 = True Or Ace2 = True Then
            CallBet()
            GoTo EndOfBetting
        End If
        If AINumbers(1) + AINumbers(2) > 18 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 16 And Bet < 300 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 13 And Bet < 100 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 9 And Bet < 50 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) < 9 Then
            CallBet()
        Else
            Fold()
        End If
Endofbetting:
    End Sub
    Private Sub Hitting()
        Panel2.visible = True
    End Sub
    Private Sub CallBet()
        Label22.Text = Label22.Text - Bet
        MsgBox("The Computer Called Your Bet")
        Panel1.Visible = False
        Hitting()
    End Sub
    Private Sub Fold()
        MsgBox("AI Folded")
        NewHand()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label20.Text = Label20.Text - Bet
        AIBetting1()
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Bet = TextBox1.Text
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Visiblecard = True
    End Sub
    Private Sub NewHand()
        Label1.Text = "  "
        Label2.Text = "  "
        Label3.Text = "  "
        Label4.Text = "  "
        Label5.Text = "  "
        Label6.Text = "  "
        Label7.Text = "  "
        Label8.Text = "  "
        Label9.Text = "  "
        Label10.Text = "  "
        Label11.Text = "  "
        Label12.Text = "  "
        Label13.Text = "  "
        Label14.Text = "  "
        Label15.Text = "  "
        Label16.Text = "  "
        Panel1.Visible = False
        Button1.Visible = True
        Label3.Visible = False
        Label4.Visible = False
        Label5.Visible = False
        Label6.Visible = False
        Label7.Visible = False
        Label8.Visible = False
        Label11.Visible = False
        Label12.Visible = False
        Label13.Visible = False
        Label14.Visible = False
        Label15.Visible = False
        Label16.Visible = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        WhichCard = WhichCard + 1
        If WhichCard = 1 Then
            Label3.Visible = True
            Numberofcards = 3
        End If
        If WhichCard = 2 Then
            Label4.Visible = True
            Numberofcards = 4
        End If
        If WhichCard = 3 Then
            Label5.Visible = True
            Numberofcards = 5
        End If
        If WhichCard = 4 Then
            Label6.Visible = True
            Numberofcards = 6
        End If
        If WhichCard = 5 Then
            Label7.Visible = True
            Numberofcards = 7
        End If
        If WhichCard = 6 Then
            Label8.Visible = True
            Numberofcards = 8
        End If
        If WhichCard = 7 Then
            MsgBox("You Have Run Out Of Cards")
        End If
        Dealme1card()
        If WhichCard = 3 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 4 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 5 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 6 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 7 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 8 And MyNumbers(1) + MyNumbers(2) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        Label23.Text = "Would You Like To Hit Again?"
End1:
    End Sub
    Private Sub bust()
        MsgBox("You Busted")
        NewHand()
    End Sub
End Class

thnx for anyhelp
john
User is offlineProfile CardPM
+Quote Post

MathewS
RE: Blackjack Application
3 Feb, 2007 - 11:43 AM
Post #2

D.I.C Regular
***

Joined: 14 May, 2002
Posts: 252



Thanked: 1 times
Dream Kudos: 1
My Contributions
MyNumbers(1) + MyNumbers(2) + MyNumbers(1)

should that not be

MyNumbers(1) + MyNumbers(2) + MyNumbers(3)

?

There are a few lines like that.
User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Blackjack Application
3 Feb, 2007 - 04:27 PM
Post #3

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(MathewS @ 3 Feb, 2007 - 12:43 PM) *

MyNumbers(1) + MyNumbers(2) + MyNumbers(1)

should that not be

MyNumbers(1) + MyNumbers(2) + MyNumbers(3)

?

There are a few lines like that.

no because in black jack you add all your cards together that you have
thnx
john

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Blackjack Application
3 Feb, 2007 - 04:58 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I think he was pointing out that you are adding the same card twice.
User is online!Profile CardPM
+Quote Post

orangeslide8
RE: Blackjack Application
4 Feb, 2007 - 04:59 AM
Post #5

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(Amadeus @ 3 Feb, 2007 - 05:58 PM) *

I think he was pointing out that you are adding the same card twice.

o thnx
sry bout that i thought he said it should be
CODE

mynumber(1) + MyNumber(2) + MyNumber(1)

thnx
i think that fixed it
john
User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: Blackjack Application
4 Feb, 2007 - 05:16 AM
Post #6

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
ok another problem. i really can't figure this out. everything works but when i bust and a new hand opens and i deal again it has the same cards
as the first hand and the same cards hit. My Random code works fine so im not sure why this is happening. anyhelp would be apprechiated.
CODE

Public Class Form1
    Dim Cards(4, 13)
    Dim CardsUsed(4, 13)
    Dim X = 0
    Dim Y = 0
    Dim MyCards(26)
    Dim AICards(26)
    Dim Z As Integer
    Dim W As Integer
    Dim AINumbers(26)
    Dim MyNumbers(26)
    Dim Bet As Integer
    Dim Visiblecard As Boolean
    Dim Ace1 As Boolean
    Dim Ace2 As Boolean
    Dim Ace3 As Boolean
    Dim Ace4 As Boolean
    Dim Ace5 As Boolean
    Dim WhichCard As Integer
    Dim Numberofcards As Integer
    Private Sub AssignmyCards()
        Label1.Text = MyCards(1)
        Label2.Text = MyCards(2)
        Label3.Text = MyCards(3)
        Label4.Text = MyCards(4)
        Label5.Text = MyCards(5)
        Label6.Text = MyCards(6)
        Label7.Text = MyCards(7)
        Label8.Text = MyCards(8)
    End Sub
    Private Sub AssignAICards()
        Label9.Text = AICards(1)
        Label10.Text = AICards(2)
        Label11.Text = AICards(3)
        Label12.Text = AICards(4)
        Label13.Text = AICards(5)
        Label14.Text = AICards(6)
        Label15.Text = AICards(7)
        Label16.Text = AICards(8)
    End Sub
    Private Sub SetCards()
        Cards(1, 1) = ("Ace Of Dimonds")
        Cards(1, 2) = ("Two Of Dimonds")
        Cards(1, 3) = ("Three Of Dimonds")
        Cards(1, 4) = ("Four Of Dimonds")
        Cards(1, 5) = ("Five Of Dimonds")
        Cards(1, 6) = ("Six Of Dimonds")
        Cards(1, 7) = ("Seven Of Dimonds")
        Cards(1, 8) = ("Eight Of Dimonds")
        Cards(1, 9) = ("Nine Of Dimonds")
        Cards(1, 10) = ("Ten Of Dimonds")
        Cards(1, 11) = ("Jack Of Dimonds")
        Cards(1, 12) = ("Queen Of Dimonds")
        Cards(1, 13) = ("King Of Dimonds")

        Cards(2, 1) = ("Ace Of Spades")
        Cards(2, 2) = ("Two Of Spades")
        Cards(2, 3) = ("Three Of Spades")
        Cards(2, 4) = ("Four Of Spades")
        Cards(2, 5) = ("Five Of Spades")
        Cards(2, 6) = ("Six Of Spades")
        Cards(2, 7) = ("Seven Of Spades")
        Cards(2, 8) = ("Eight Of Spades")
        Cards(2, 9) = ("Nine Of Spades")
        Cards(2, 10) = ("Ten Of Spades")
        Cards(2, 11) = ("Jack Of Spades")
        Cards(2, 12) = ("Queen Of Spades")
        Cards(2, 13) = ("King Of Spades")

        Cards(3, 1) = ("Ace Of Clubs")
        Cards(3, 2) = ("Two Of Clubs")
        Cards(3, 3) = ("Three Of Clubs")
        Cards(3, 4) = ("Four Of Clubs")
        Cards(3, 5) = ("Five Of Clubs")
        Cards(3, 6) = ("Six Of Clubs")
        Cards(3, 7) = ("Seven Of Clubs")
        Cards(3, 8) = ("Eight Of Clubs")
        Cards(3, 9) = ("Nine Of Clubs")
        Cards(3, 10) = ("Ten Of Clubs")
        Cards(3, 11) = ("Jack Of Clubs")
        Cards(3, 12) = ("Queen Of Clubs")
        Cards(3, 13) = ("King Of Clubs")

        Cards(4, 1) = ("Ace Of Hearts")
        Cards(4, 2) = ("Two Of Hearts")
        Cards(4, 3) = ("Three Of Hearts")
        Cards(4, 4) = ("Four Of Hearts")
        Cards(4, 5) = ("Five Of Hearts")
        Cards(4, 6) = ("Six Of Hearts")
        Cards(4, 7) = ("Seven Of Hearts")
        Cards(4, 8) = ("Eight Of Hearts")
        Cards(4, 9) = ("Nine Of Hearts")
        Cards(4, 10) = ("Ten Of Hearts")
        Cards(4, 11) = ("Jack Of Hearts")
        Cards(4, 12) = ("Queen Of Hearts")
        Cards(4, 13) = ("King Of Hearts")
    End Sub
    Private Sub SetCardsused()
        CardsUsed(1, 1) = False
        CardsUsed(1, 2) = False
        CardsUsed(1, 3) = False
        CardsUsed(1, 4) = False
        CardsUsed(1, 5) = False
        CardsUsed(1, 6) = False
        CardsUsed(1, 7) = False
        CardsUsed(1, 8) = False
        CardsUsed(1, 9) = False
        CardsUsed(1, 10) = False
        CardsUsed(1, 11) = False
        CardsUsed(1, 12) = False
        CardsUsed(1, 13) = False

        CardsUsed(2, 1) = False
        CardsUsed(2, 2) = False
        CardsUsed(2, 3) = False
        CardsUsed(2, 4) = False
        CardsUsed(2, 5) = False
        CardsUsed(2, 6) = False
        CardsUsed(2, 7) = False
        CardsUsed(2, 8) = False
        CardsUsed(2, 9) = False
        CardsUsed(2, 10) = False
        CardsUsed(2, 11) = False
        CardsUsed(2, 12) = False
        CardsUsed(2, 13) = False

        CardsUsed(3, 1) = False
        CardsUsed(3, 2) = False
        CardsUsed(3, 3) = False
        CardsUsed(3, 4) = False
        CardsUsed(3, 5) = False
        CardsUsed(3, 6) = False
        CardsUsed(3, 7) = False
        CardsUsed(3, 8) = False
        CardsUsed(3, 9) = False
        CardsUsed(3, 10) = False
        CardsUsed(3, 11) = False
        CardsUsed(3, 12) = False
        CardsUsed(3, 13) = False

        CardsUsed(4, 1) = False
        CardsUsed(4, 2) = False
        CardsUsed(4, 3) = False
        CardsUsed(4, 4) = False
        CardsUsed(4, 5) = False
        CardsUsed(4, 6) = False
        CardsUsed(4, 7) = False
        CardsUsed(4, 8) = False
        CardsUsed(4, 9) = False
        CardsUsed(4, 10) = False
        CardsUsed(4, 11) = False
        CardsUsed(4, 12) = False
        CardsUsed(4, 13) = False
    End Sub
    Private Sub Dealme1card()
        X = X + 1
Top:    Randomize()
        Z = Int(Rnd() * 12) + 1
        W = Int(Rnd() * 3) + 1
        If CardsUsed(W, Z) = True Then
            GoTo Top
        End If
        MyCards(X) = Cards(W, Z)
        CardsUsed(W, Z) = True
        If Z > 10 Then
            Z = 10
        End If
        MyNumbers(X) = Z
        AssignmyCards()
    End Sub
    Private Sub DealAI1Card()
        Y = Y + 1
Top:    Randomize()
        Z = Int(Rnd() * 12) + 1
        W = Int(Rnd() * 3) + 1
        If CardsUsed(W, Z) = True Then
            GoTo Top
        End If
        AICards(Y) = Cards(W, Z)
        CardsUsed(W, Z) = True
        If Z > 10 Then
            Z = 10
        End If
        AINumbers(Y) = Z
        If Visiblecard = False Then
            GoTo Bottom
        End If
        AssignAICards()
Bottom:
    End Sub
    Private Sub betting()
        Panel1.Visible = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SetCards()
        SetCardsused()
        Dealme1card()
        Dealme1card()
        DealAI1Card()
        DealAI1Card()
        Button1.Visible = False
        betting()
    End Sub
    Private Sub AIBetting1()
        If AINumbers(1) = 1 Then
            Ace1 = True
        End If
        If AINumbers(2) = 1 Then
            Ace2 = True
        End If
        If Ace1 = True Or Ace2 = True Then
            CallBet()
            GoTo EndOfBetting
        End If
        If AINumbers(1) + AINumbers(2) > 18 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 16 And Bet < 300 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 13 And Bet < 100 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) > 9 And Bet < 50 Then
            CallBet()
            GoTo Endofbetting
        End If
        If AINumbers(1) + AINumbers(2) < 9 Then
            CallBet()
        Else
            Fold()
        End If
Endofbetting:
    End Sub
    Private Sub Hitting()
        Panel2.visible = True
    End Sub
    Private Sub CallBet()
        Label22.Text = Label22.Text - Bet
        MsgBox("The Computer Called Your Bet")
        Panel1.Visible = False
        Hitting()
    End Sub
    Private Sub Fold()
        MsgBox("AI Folded")
        NewHand()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label20.Text = Label20.Text - Bet
        AIBetting1()
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Bet = TextBox1.Text
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Visiblecard = True
    End Sub
    Private Sub NewHand()
        Label1.Text = "  "
        Label2.Text = "  "
        Label3.Text = "  "
        Label4.Text = "  "
        Label5.Text = "  "
        Label6.Text = "  "
        Label7.Text = "  "
        Label8.Text = "  "
        Label9.Text = "  "
        Label10.Text = "  "
        Label11.Text = "  "
        Label12.Text = "  "
        Label13.Text = "  "
        Label14.Text = "  "
        Label15.Text = "  "
        Label16.Text = "  "
        Panel1.Visible = False
        Button1.Visible = True
        Label3.Visible = False
        Label4.Visible = False
        Label5.Visible = False
        Label6.Visible = False
        Label7.Visible = False
        Label8.Visible = False
        Label11.Visible = False
        Label12.Visible = False
        Label13.Visible = False
        Label14.Visible = False
        Label15.Visible = False
        Label16.Visible = False
      panel2.visible = False
      Textbox1.Text = “  “
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        WhichCard = WhichCard + 1
        If WhichCard = 1 Then
            Label3.Visible = True
            Numberofcards = 3
        End If
        If WhichCard = 2 Then
            Label4.Visible = True
            Numberofcards = 4
        End If
        If WhichCard = 3 Then
            Label5.Visible = True
            Numberofcards = 5
        End If
        If WhichCard = 4 Then
            Label6.Visible = True
            Numberofcards = 6
        End If
        If WhichCard = 5 Then
            Label7.Visible = True
            Numberofcards = 7
        End If
        If WhichCard = 6 Then
            Label8.Visible = True
            Numberofcards = 8
        End If
        If WhichCard = 7 Then
            MsgBox("You Have Run Out Of Cards")
        End If
        Dealme1card()
        If WhichCard = 3 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 4 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) + MyNumbers(4) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 5 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) + MyNumbers(4) + MyNumbers(5) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 6 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) + MyNumbers(4) + MyNumbers(5) + MyNumbers(6) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 7 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) + MyNumbers(4) + MyNumbers(5) + MyNumbers(6) + MyNumbers(7) > 21 Then
            bust()
            GoTo end1
        End If
        If WhichCard = 8 And MyNumbers(1) + MyNumbers(2) + MyNumbers(3) + MyNumbe8s(4) + MyNumbers(5) + MyNumbers(6) + MyNumbers(7) + MyNumbers(1) > 21 Then
            bust()
            GoTo end1
        End If
        Label23.Text = "Would You Like To Hit Again?"
End1:
    End Sub
    Private Sub bust()
        MsgBox("You Busted")
        NewHand()
    End Sub
End Class

thnx
john

User is offlineProfile CardPM
+Quote Post

MathewS
RE: Blackjack Application
4 Feb, 2007 - 09:39 AM
Post #7

D.I.C Regular
***

Joined: 14 May, 2002
Posts: 252



Thanked: 1 times
Dream Kudos: 1
My Contributions
Randomize() only has to be called once, try just having one call to that function in the form_load event.

try this
CODE

Public Class Form1
    Dim Cards(4, 13)
    Dim CardsUsed(4, 13)
    Dim X = 0
    Dim Y = 0
    Dim MyCards(26)
    Dim AICards(26)
    Dim Z As Integer
    Dim W As Integer
    Dim AINumbers(26)
    Dim MyNumbers(26)
    Dim Bet As Integer
    Dim Visiblecard As Boolean
    Dim Ace1 As Boolean
    Dim Ace2 As Boolean
    Dim Ace3 As Boolean
    Dim Ace4 As Boolean
    Dim Ace5 As Boolean
    Dim WhichCard As Integer
    Dim Numberofcards As Integer
    Private Sub AssignmyCards()
        Label1.Text = MyCards(1)
        Label2.Text = MyCards(2)
        Label3.Text = MyCards(3)
        Label4.Text = MyCards(4)
        Label5.Text = MyCards(5)
        Label6.Text = MyCards(6)
        Label7.Text = MyCards(7)
        Label8.Text = MyCards(8)
    End Sub
    Private Sub AssignAICards()
        Label9.Text = AICards(1)
        Label10.Text = AICards(2)
        Label11.Text = AICards(3)
        Label12.Text = AICards(4)
        Label13.Text = AICards(5)
        Label14.Text = AICards(6)
        Label15.Text = AICards(7)
        Label16.Text = AICards(8)
    End Sub
    Private Sub SetCards()
        Cards(1, 1) = ("Ace Of Dimonds")
        Cards(1, 2) = ("Two Of Dimonds")
        Cards(1, 3) = ("Three Of Dimonds")
        Cards(1, 4) = ("Four Of Dimonds")
        Cards(1, 5) = ("Five Of Dimonds")
        Cards(1, 6) = ("Six Of Dimonds")
        Cards(1, 7) = ("Seven Of Dimonds")
        Cards(1, 8) = ("Eight Of Dimonds")
        Cards(1, 9) = ("Nine Of Dimonds")
        Cards(1, 10) = ("Ten Of Dimonds")
        Cards(1, 11) = ("Jack Of Dimonds")
        Cards(1, 12) = ("Queen Of Dimonds")
        Cards(1, 13) = ("King Of Dimonds")

        Cards(2, 1) = ("Ace Of Spades")
        Cards(2, 2) = ("Two Of Spades")
        Cards(2, 3) = ("Three Of Spades")
        Cards(2, 4) = ("Four Of Spades")
        Cards(2, 5) = ("Five Of Spades")
        Cards(2, 6) = ("Six Of Spades")
        Cards(2, 7) = ("Seven Of Spades")
        Cards(2, 8) = ("Eight Of Spades")
        Cards(2, 9) = ("Nine Of Spades")
        Cards(2, 10) = ("Ten Of Spades")
        Cards(2, 11) = ("Jack Of Spades")
        Cards(2, 12) = ("Queen Of Spades")
        Cards(2, 13) = ("King Of Spades")

        Cards(3, 1) = ("Ace Of Clubs")
        Cards(3, 2) = ("Two Of Clubs")
        Cards(3, 3) = ("Three Of Clubs")
        Cards(3, 4) = ("Four Of Clubs")
        Cards(3, 5) = ("Five Of Clubs")
        Cards(3, 6) = ("Six Of Clubs")
        Cards(3, 7) = ("Seven Of Clubs")
        Cards(3, 8) = ("Eight Of Clubs")
        Cards(3, 9) = ("Nine Of Clubs")
        Cards(3, 10) = ("Ten Of Clubs")
        Cards(3, 11) = ("Jack Of Clubs")
        Cards(3, 12) = ("Queen Of Clubs")
        Cards(3, 13) = ("King Of Clubs")

        Cards(4, 1) = ("Ace Of Hearts")
        Cards(4, 2) = ("Two Of Hearts")
        Cards(4, 3) = ("Three Of Hearts")
        Cards(4, 4) = ("Four Of Hearts")
        Cards(4, 5) = ("Five Of Hearts")
        Cards(4, 6) = ("Six Of Hearts")
        Cards(4, 7) = ("Seven Of Hearts")
        Cards(4, 8) = ("Eight Of Hearts")
        Cards(4, 9) = ("Nine Of Hearts")
        Cards(4, 10) = ("Ten Of Hearts")
        Cards(4, 11) = ("Jack Of Hearts")
        Cards(4, 12) = ("Queen Of Hearts")
        Cards(4, 13) = ("King Of Hearts")
    End Sub
    Private Sub SetCardsused()
        CardsUsed(1, 1) = False
        CardsUsed(1, 2) = False
        CardsUsed(1, 3) = False
        CardsUsed(1, 4) = False
        CardsUsed(1, 5) = False
        CardsUsed(1, 6) = False
        CardsUsed(1, 7) = False
        CardsUsed(1, 8) = False
        CardsUsed(1, 9) = False
        CardsUsed(1, 10) = False
        CardsUsed(1, 11) = False
        CardsUsed(1, 12) = False
        CardsUsed(1, 13) = False

        CardsUsed(2, 1) = False
        CardsUsed(2, 2) = False
        CardsUsed(2, 3) = False
        CardsUsed(2, 4) = False
        CardsUsed(2, 5) = False
        CardsUsed(2, 6) = False
        CardsUsed(2, 7) = False
        CardsUsed(2, 8) = False
        CardsUsed(2, 9) = False
        CardsUsed(2, 10) = False
        CardsUsed(2, 11) = False
        CardsUsed(2, 12) = False
        CardsUsed(2, 13) = False

        CardsUsed(3, 1) = False
        CardsUsed(3, 2) = False
        CardsUsed(3, 3) = False
        CardsUsed(3, 4) = False
        CardsUsed(3, 5) = False
        CardsUsed(3, 6) = False
        CardsUsed(3, 7) = False
        CardsUsed(3, 8) = False
        CardsUsed(3, 9) = False
        CardsUsed(3, 10) = False
        CardsUsed(3, 11) = False
        CardsUsed(3, 12) = False
        CardsUsed(3, 13) = False

        CardsUsed(4, 1) = False
        CardsUsed(4, 2) = False
        CardsUsed(4, 3) = False
        CardsUsed(4, 4) = False
        CardsUsed(4, 5) = False
        CardsUsed(4, 6) = False
        CardsUsed(4, 7) = False
        CardsUsed(4, 8) = False
        CardsUsed(4, 9) = False
        CardsUsed(4, 10) = False
        CardsUsed(4, 11) = False
        CardsUsed(4, 12) = False
        CardsUsed(4, 13) = False
    End Sub
    Private Sub Dealme1card()
        X = X + 1
Top:    Z = Int(Rnd() * 12) + 1
        W = Int(Rnd() * 3) + 1
        If CardsUsed(W, Z) = True Then
            GoTo Top
        En