Jump to content
• Advertisement

# Blackjack MiniGame (VB6)

This topic is 3927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

OK, I'm on making a game in VB6, I'm going to be adding a mini-casino to it, the first game in the casino is going to be BlackJack. Its just going to be text (not pictures) I've never made a card game before as I'm quite new to VB, I was just wondering what would be the most suitable way of making it deal random cards? I was thinking something like ' Start of code Dim Roll As Integer Dim Card As String Randomize Roll = Int(52 * rnd) + 1 If Roll = 1 Then Card = "Ace" Else If Roll = 2 Then Card = "Two" and so on.... this will be a lot of code though, i was wondering if there would be an easier way? Cheers u1bd2005.

#### Share this post

##### Share on other sites
Advertisement
You're going to want to make a deck of 52 cards. Since in Blackjack the suit doesn't matter, you can ignore suit and just add 4 1's, 4 2's, etc to the deck which will be some sort of list or array. Then shuffle the array, make an index variable that points to the top of the deck and start dealing cards.

Actually simulating the thing you're trying to simulate is usually a good idea. OK, with blackjack this doesn't matter too much. About the only way simply choosing a random number from 1 through 13 would go wrong is if you dealt 5 aces or something. If you simulate a deck of cards, little things like that can't happen.

As for printing the name of a card, a lookup table would be easiest. Make an array of strings whose index is the name of the card. By that I means index 1 is "Ace", 2 is "Deuce", 3 is "Three", etc. That way you don't have to do the giant switch statement either. A giant switch statement is usually a sign that you could do it a better way.

#### Share this post

##### Share on other sites
I'm not very familiar with VB6, but you need to look into arrays.

You could have an array of suits and card names such as -
suit[4] = { "Hearts" , "Diamonds" , "Clubs" , "Spades" };
card[13] = { "Ace" , "one" ... "ten" , "Jack" , "Queen" , "King" };

You could then use something like -
cardname = card[cardno % 13] + "of" + cardsuit[cardno/13]
( % is modulo )

You could also have a deck array (of 52 cards), shuffle this deck in some way then draw a card from each successive element of the array.

The way you are doing it would allow the same card to be drawn more than once (and end up as a very bloated piece of code)

#### Share this post

##### Share on other sites
You should make a Card class and a Deck class which would contain 52 cards. Then you can use these for every card game you make. I made these for VB6 a while ago, I could give you the code if you want but its probably better if you do it yourself so you can udnerstand it better.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013546
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!