Ok ive made a VB blackjack game. just wanted to know if anyone can spot any problems (its homework)

Public pc1 As New card
Public pc2 As New card
Public pc3 As New card
Public pc4 As New card
Public pc5 As New card

Public dc1 As New card
Public dc2 As New card
Public dc3 As New card
Public dc4 As New card
Public dc5 As New card

Public playertotal As Integer
Public dealertotal As Integer

Public pcards As Integer
Public dcards As Integer

Public playerwins As Integer
Public dealerwins As Integer

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Randomize()
deal()
End Sub

Private Sub Button1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button1.Click
phit()
bustcheck()
End Sub

Private Sub Button2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button2.Click

While dealertotal < playertotal And dcards < 5
dealerhit()
End While

check()
deal()
End Sub

Sub deal()

TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

TextBox11.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""

pc1.main()
pc2.main()

dc1.main()
dc2.main()

TextBox1.Text = pc1.name
TextBox2.Text = pc2.name

TextBox9.Text = dc1.name
TextBox10.Text = dc2.name

playertotal = pc1.value + pc2.value
dealertotal = dc1.value + dc2.value

pcards = 2
dcards = 2

TextBox7.Text = CStr(playerwins)
TextBox8.Text = CStr(dealerwins)
If playertotal = 22 Then
deal()
End If
If dealertotal = 22 Then
deal()
End If

End Sub

Sub check()

If dealertotal > 21 Then
MsgBox("Dealer bust")
playerwins = playerwins + 1
Exit Sub
End If

If pcards = 5 And dcards = 5 Then
If playertotal > dealertotal Then
MsgBox("Player has the best trick")
playerwins = playerwins + 1
Exit Sub
Else
MsgBox("Dealer has the best trick")
dealerwins = dealerwins + 1
Exit Sub
End If
End If

If pcards = 5 Then
MsgBox("Player has a 5 card trick")
playerwins = playerwins + 1
Exit Sub
End If

If dcards = 5 Then
MsgBox("Dealer has a 5 card trick")
dealerwins = dealerwins + 1
Exit Sub
End If

If playertotal > dealertotal Then
MsgBox("Player wins")
playerwins = playerwins + 1
Exit Sub
Else
MsgBox("Dealer wins")
dealerwins = dealerwins + 1
Exit Sub
End If

End Sub

Sub bustcheck()
If playertotal > 21 Then
MsgBox("Player bust")
dealerwins = dealerwins + 1
deal()
Exit Sub
End If
End Sub

Sub dealerhit()

Select Case dcards

Case 2
dc3.main()

dealertotal = dealertotal + dc3.value
dcards = dcards + 1

TextBox11.Text = dc3.name

Exit Sub
Case 3
dc4.main()

dealertotal = dealertotal + dc4.value
dcards = dcards + 1

TextBox13.Text = dc4.name

Exit Sub
Case 4

dc5.main()

dealertotal = dealertotal + dc5.value
dcards = dcards + 1

TextBox14.Text = dc5.name

Exit Sub
End Select

Exit Sub

End Sub

Sub phit()

Select Case pcards

Case 2
pc3.main()

TextBox3.Text = pc3.name
playertotal = playertotal + pc3.value

pcards = pcards + 1

bustcheck()

Exit Sub

Case 3
pc4.main()

TextBox4.Text = pc4.name
playertotal = playertotal + pc4.value

pcards = pcards + 1

bustcheck()

Exit Sub

Case 4
pc5.main()

TextBox5.Text = pc5.name
playertotal = playertotal + pc5.value

pcards = pcards + 1

Exit Sub
End Select

Exit Sub

End Sub
End Class

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

What's the requirements of your assignment.

Do you have to use classes? What about splitting when you get a pair?

i can do it however i want - just has to be in VB.NET 2003
the brief is simply to make a blackjack/pontoon game

right now it works very well but i think i may remake it and use an array for the cards - only i used classes is i got the carsds to be random and have a human friendly name by using a class module shown below:

OptionStrictOff
OptionExplicitOn
 
FriendClass card
'Card.cls - Class module for the cards used in the blackjack game
'James Duncan Bennet 2006 - james.bennet1@ntlworld.com
 
Public name As String
Public id As Short
Public value As Short
 
Sub main() 'This doesnt have to be called main, but cant be bothered changing it now :)
 
id = CDbl(CStr(Int(Rnd() * 13))) + 1
 
'From the .NET version, dont know if its ok - The +1 is to stop id of 0, could do without it but hey....
 
Select Case id
 
Case 1 : name = "Ace Low"
value = 1
Case 2 : name = "2"
value = 2
Case 3 : name = "3"
value = 3
Case 4 : name = "4"
value = 4
Case 5 : name = "5"
value = 5
Case 6 : name = "6"
value = 6
Case 7 : name = "7"
value = 7
Case 8 : name = "8"
value = 8
Case 9 : name = "9"
value = 9
Case 10 : name = "10"
value = 10
Case 11 : name = "Jack"
value = 10
Case 12 : name = "Queen"
value = 10
Case 13 : name = "King"
value = 10
Case 14 : name = "Ace High"
value = 11
 
End Select
End Sub
EndClass

i just initialise the card by doing e.g dc1.main which randomises it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.