I've started writing a very basic game of 21. I'm just using shapes and labels to make up the cards. I did a quick search for other 21 games and found one similar the the type I want to write. The code is a bit on the long side though. Is there an easier way of doing this? I was thinking of using an array for the cards but I could use a point in the right direction.
I've attached the form I found. It looks like it still needs a lot of work but I'm only interested in how to use and call the cards, without spending the next three weeks typing the code.
If anyone knows of any step by step guides that would be great too.
How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?
Hi, I haven't actually looked at the form (sorry, I don't have enough time), but something you might wish to have a look at is this tutorial over here:
It is a *bit* more advanced than using shapes and labels, but you might be a lot more pleased with the look of your program by using it. It describes how to use the same 'deck' of cards which the windows card games like solitaire use. Included is a demo of a certain card game (I'm not sure which one ), which will give you a fairly good idea as to how to actually implement the tutorial.
Also, don't be put off about the length of code, some of the simplest code you can write would be pages long, and I've written some single liners which would bamboozle you for months . Blackjack is a good project to work on because there are a couple of nice problems to solve, and there are different ways of doing so, you might find a way of doing it which you find is a lot neater/shorter/nicer/faster than the way you see.
I would reccomend making a Deck class. Write member functions to create the cards, shuffle the deck, cut the deck, and a way to access an array of 52 cards. I would also make a Card UDT to isolate indiviual cards. When taking cards, keep a static variable of the card that is to be drawn, and increment it when was is taken. Once you have a good card class, you have it made because the rest is just like writing out the rules of a game.
nice code rat. I've got some ancient code here that shuffles a deck pretty well. [edit] make iteration very high for better shuffling. Arround 100000 works ver nicely.[/edit]
VB Code:
Type Card
CardName as String
CardValue as Long
SuitIndex as Long
End Type
Dim Cards(51) as Card
Sub Shuffle(iterations as Long)
Dim replaceBuff as Card, lCounter1 as Long,Index1 as Long, Index2 as Long
Private Sub ShuffleCards()
Dim TempValue As Integer
Dim LoopCounter As Integer
Dim ItemPicked As Integer
Dim Remaining As Integer
'One Card Shuffle
'Initialize CardNumber
For LoopCounter = 1 To 52
CardNumber(LoopCounter) = LoopCounter
Next LoopCounter
'Work through remaining values
For Remaining = 52 To 2 Step -1
ItemPicked = Int(Rnd * Remaining) + 1
TempValue = CardNumber(Remaining)
CardNumber(Remaining) = CardNumber(ItemPicked)
CardNumber(ItemPicked) = TempValue
Next Remaining
End Sub
This is the code that's in my course book.
How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?