soo..... problems:
-some of the cards won't flip (this appears to be random)
-BIG issue working out how to get the program to always use all three cards for computer even when user ends with just two.
i know its messy, and still a long way from finished, but id REALLLYY appreciate some feedback
thx!
Code:
Public Class Form2
Dim com1 As Integer 'computers three random cards
Dim com2 As Integer 'will be used in case select for card pix
Dim com3 As Integer
Dim play1 As Integer 'players three random cards
Dim play2 As Integer
Dim play3 As Integer
Dim ace1 As Integer = 1 'lets player choose ace val
Dim ace2 As Integer = 11
Dim playScore As Integer = 0 'players total score
Dim comScore As Integer = 0 'coms total score
Const MIN As Integer = 1
Const MAX As Integer = 13
Dim turn As Integer = 0
Const SCORE As Integer = 21 'goal (equal or under)
Private Sub frm21_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize() 'randomize card values
com1 = Int((MAX - MIN + 1) * Rnd() * MIN)
com2 = Int((MAX - MIN + 1) * Rnd() * MIN)
com3 = Int((MAX - MIN + 1) * Rnd() * MIN)
play1 = Int((MAX - MIN + 1) * Rnd() * MIN)
play2 = Int((MAX - MIN + 1) * Rnd() * MIN)
Select Case turn
Case 2
play3 = 0
imgCard6.Visible = False
Case 3
play3 = Int((MAX - MIN + 1) * Rnd() * MIN)
imgCard6.Visible = True
End Select
btnAgain.Visible = False
btnAgain.Enabled = False
btnDraw.Visible = True
btnDraw.Enabled = True
btnCheck.Visible = False
btnCheck.Enabled = False
End Sub
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
turn += 1
Select Case turn
Case 1
lblComDeal.Visible = True
imgCard1.Visible = True
lblPlayDeal.Visible = True
imgCard4.Visible = True
Case 2
imgCard1.Visible = True
imgCard4.Visible = True
imgCard2.Visible = True
imgCard5.Visible = True
lblChoose.Visible = True
btnCheck.Enabled = True
btnCheck.Visible = True
Case 3
imgCard1.Visible = True
imgCard4.Visible = True
imgCard2.Visible = True
imgCard5.Visible = True
imgCard3.Visible = True
imgCard6.Visible = True
lblChoose.Visible = False
btnDraw.Enabled = False
End Select
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
lblChoose.Visible = False
Select Case turn
Case 2
Select Case com1
Case 1
If Form1.cmbAce.Text = "Play with ace as one" Then
comScore += 1
ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
comScore += 11
End If
imgCard1.Image = Blackjack_Fix.My.Resources.sa
Case 2
imgCard1.Image = Blackjack_Fix.My.Resources.d_2
comScore += 2
Case 3
imgCard1.Image = Blackjack_Fix.My.Resources.club_3
comScore += 3
Case 4
imgCard1.Image = Blackjack_Fix.My.Resources.h4
comScore += 4
Case 5
imgCard1.Image = Blackjack_Fix.My.Resources.s5
comScore += 5
Case 6
imgCard1.Image = Blackjack_Fix.My.Resources.d_6
comScore += 6
Case 7
imgCard1.Image = Blackjack_Fix.My.Resources.club_7
comScore += 7
Case 8
imgCard1.Image = Blackjack_Fix.My.Resources.h8
comScore += 8
Case 9
imgCard1.Image = Blackjack_Fix.My.Resources.s9
comScore += 9
Case 10
imgCard1.Image = Blackjack_Fix.My.Resources.d_10
comScore += 10
Case 11
imgCard1.Image = Blackjack_Fix.My.Resources.jackdiamond
comScore += 11
Case 12
imgCard1.Image = Blackjack_Fix.My.Resources.queenheart
comScore += 12
Case 13
imgCard1.Image = Blackjack_Fix.My.Resources.kingheart
comScore += 13
End Select
Select Case com2
Case 1
If Form1.cmbAce.Text = "Play with ace as one" Then
comScore += 1
ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
comScore += 11
End If
imgCard2.Image = Blackjack_Fix.My.Resources.sa
Case 2
imgCard2.Image = Blackjack_Fix.My.Resources.d_2
comScore += 2
Case 3
imgCard2.Image = Blackjack_Fix.My.Resources.club_3
comScore += 3
Case 4
imgCard2.Image = Blackjack_Fix.My.Resources.h4
comScore += 4
Case 5
imgCard2.Image = Blackjack_Fix.My.Resources.s5
comScore += 5
Case 6
imgCard2.Image = Blackjack_Fix.My.Resources.d_6
comScore += 6
Case 7
imgCard2.Image = Blackjack_Fix.My.Resources.club_7
comScore += 7
Case 8
imgCard2.Image = Blackjack_Fix.My.Resources.h8
comScore += 8
Case 9
imgCard2.Image = Blackjack_Fix.My.Resources.s9
comScore += 9
Case 10
imgCard2.Image = Blackjack_Fix.My.Resources.d_10
comScore += 10
Case 11
imgCard2.Image = Blackjack_Fix.My.Resources.jackdiamond
comScore += 11
Case 12
imgCard2.Image = Blackjack_Fix.My.Resources.queenheart
comScore += 12
Case 13
imgCard2.Image = Blackjack_Fix.My.Resources.kingheart
comScore += 13
End Select
Select Case com3
Case 1
If Form1.cmbAce.Text = "Play with ace as one" Then
comScore += 1
ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
comScore += 11
End If
imgCard3.Image = Blackjack_Fix.My.Resources.sa
Case 2
imgCard3.Image = Blackjack_Fix.My.Resources.d_2
comScore += 2
Case 3
imgCard3.Image = Blackjack_Fix.My.Resources.club_3
comScore += 3
Case 4
imgCard3.Image = Blackjack_Fix.My.Resources.h4
comScore += 4
Case 5
imgCard3.Image = Blackjack_Fix.My.Resources.s5
comScore += 5
Case 6
imgCard3.Image = Blackjack_Fix.My.Resources.d_6
comScore += 6
Case 7
imgCard3.Image = Blackjack_Fix.My.Resources.club_7
comScore += 7
Case 8
imgCard3.Image = Blackjack_Fix.My.Resources.h8
comScore += 8
Case 9
imgCard3.Image = Blackjack_Fix.My.Resources.s9
comScore += 9
Case 10
imgCard3.Image = Blackjack_Fix.My.Resources.d_10
comScore += 10
Case 11
imgCard3.Image = Blackjack_Fix.My.Resources.jackdiamond
comScore += 11
Case 12
imgCard3.Image = Blackjack_Fix.My.Resources.queenheart
comScore += 12
Case 13
imgCard3.Image = Blackjack_Fix.My.Resources.kingheart
comScore += 13
End Select
comScore = com1 + com2 + com3
There is an awful lot of unnecessary code there...
The first part is Select Case turn in frm21_Load , because at that point the value of turn will be 0, so none of the cases will run.
The much bigger part is the code in btnCheck_Click, which repeats what is essentially the same block of code. If you create a sub/function that contains the part that gets repeated (and pass parameters as apt), all of your code would have fit in one post.
The sub could be like this (I'm not sure "as Image" is correct):
Code:
Private Function AddScore(p_Card as Integer, p_Image as Image) as Integer
Select Case p_Card
Case 1
p_Image = Blackjack_Fix.My.Resources.sa
If Form1.cmbAce.Text = "Play with ace as one" Then
Return 1
ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
Return 11
End If
Case 2
p_Image = Blackjack_Fix.My.Resources.d_2
Return 2
Case 3
p_Image = Blackjack_Fix.My.Resources.club_3
Return 3
Case 4
p_Image = Blackjack_Fix.My.Resources.h4
Return 4
Case 5
p_Image = Blackjack_Fix.My.Resources.s5
Return 5
Case 6
p_Image = Blackjack_Fix.My.Resources.d_6
Return 6
Case 7
p_Image = Blackjack_Fix.My.Resources.club_7
Return 7
Case 8
p_Image = Blackjack_Fix.My.Resources.h8
Return 8
Case 9
p_Image = Blackjack_Fix.My.Resources.s9
Return 9
Case 10
p_Image = Blackjack_Fix.My.Resources.d_10
Return 10
Case 11
p_Image = Blackjack_Fix.My.Resources.jackdiamond
Return 11
Case 12
p_Image = Blackjack_Fix.My.Resources.queenheart
Return 12
Case 13
p_Image = Blackjack_Fix.My.Resources.kingheart
Return 13
End Select
End Function
Then you can replace the "Select Case com1/com2/com3" blocks with this:
thanks si that was a huge help I've been working on getting the computer to always draw three cards even when the player ends with only 2. im thinking 2 different counters- one for com and one for player. your edits were a huge help but now i cant seem to get the images of the cards to show up. any ideas?
In that case change p_Image inside the routine to p_Image.Image , and when you call the routine pass the control name (you are likely to need to change p_Image As Image too, to the type of the control).
oh sorry. i clicked draw twice, so the player would have 2 cards. after two cards you can check the scores and end the game. ive been trying to make it so the computer always gets three cards- in the picture it's either now drawing three but the third one doesnt show up, or just b.s.ing the score (which it has been doing lately. the coms score is almost always in the low fifties.).
edit:
i've put in labels in form load to show the values before i draw the cards so i can verify the values. this is what i got: (i cut up the pic a bit to make it smaller)
Last edited by Carmelsundae; Apr 1st, 2011 at 12:12 PM.
In btnCheck_Click you increase playScore and comScore based on the current cards, but you also re-add the values of the previous cards (eg: comScore always increases by the value of all 3 cards, and even does it twice!).
You should either add the values for only the new cards, or reset the variables and then add the values for all cards.