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