ok, so our VB.net teacher is making us do this ridiculous project where we have to program a game of blackjack. i know how to make the buttons (hit, stand, clear, exit) and such, not a prob. thing is, we have to make a random card appear in a picture box control, and i dont know how to make the picture box respond to the Hit button. basically, i need a card image to pop up in the picture box when i click the Hit button. oh..and we're not allowed to use advanced stuff like shells or anything; we've only learned as far as loops. i need help ASAP.
Blackjack
Started by
trogdor
, Feb 28 2005 06:35 PM
#1
Posted 28 February 2005 - 06:35 PM
ok, so our VB.net teacher is making us do this ridiculous project where we have to program a game of blackjack. i know how to make the buttons (hit, stand, clear, exit) and such, not a prob. thing is, we have to make a random card appear in a picture box control, and i dont know how to make the picture box respond to the Hit button. basically, i need a card image to pop up in the picture box when i click the Hit button. oh..and we're not allowed to use advanced stuff like shells or anything; we've only learned as far as loops. i need help ASAP.
#2
Posted 02 March 2005 - 08:30 PM
Sounds similar to the dice game I had to do when learning VB6... well it was a while ago but I can give you a rough gist of what to do and you can look up the correct code later.
First you need a set of images of playing cards.
This bit goes in the general area:
Set up an array (if you have covered those yet - otherwise you will need a couple of fairly lengthy case statements) with 3 sets of values - a number 0-51, an image filename, and the numerical value of the card.
Attach the stuff below to the button:
The first thing the button should do is generate a random number 0-51. Save it as a variable e.g. HitNum
Use either the array values to set the image displayed and add the correct number of points to the total. (I would need to look this up - like I say it has been a while)
OR
set up 2 case statements (these are going to be long):
select case HitNum
Case='0' then Pictbox.image='aceofspades.jpg'
Case='1' then pictbox.image='twoofspades.jpg'
(etc - this may not be exactly right but kind of like that)
End case
Select case HitNum
Case='0' then PointsTotal=PointsTotal + 11
(you might want to add an extra bit in here which changes the Ace values to +1 rather than +11 if the PointsTotal is more than 21)
...etcetera
Finally a simple if statement to see whether points total is more or less than 21.
Hope this helps!
First you need a set of images of playing cards.
This bit goes in the general area:
Set up an array (if you have covered those yet - otherwise you will need a couple of fairly lengthy case statements) with 3 sets of values - a number 0-51, an image filename, and the numerical value of the card.
Attach the stuff below to the button:
The first thing the button should do is generate a random number 0-51. Save it as a variable e.g. HitNum
Use either the array values to set the image displayed and add the correct number of points to the total. (I would need to look this up - like I say it has been a while)
OR
set up 2 case statements (these are going to be long):
select case HitNum
Case='0' then Pictbox.image='aceofspades.jpg'
Case='1' then pictbox.image='twoofspades.jpg'
(etc - this may not be exactly right but kind of like that)
End case
Select case HitNum
Case='0' then PointsTotal=PointsTotal + 11
(you might want to add an extra bit in here which changes the Ace values to +1 rather than +11 if the PointsTotal is more than 21)
...etcetera
Finally a simple if statement to see whether points total is more or less than 21.
Hope this helps!
#3
Posted 02 March 2005 - 08:35 PM
Duh - if you use numbers 0-51 to name the images you can just get it to append .jpg to the number and change the picture.image to whatever that value is.
Um, I think, anyway. It would get rid of the first case statement.
Um, I think, anyway. It would get rid of the first case statement.
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users