need help with solitaire

WeavMan
03-20-2002, 12:23 PM
When we try to start a new game, it puts cards on top of one another? Why?

ChiefRedBull
03-20-2002, 03:51 PM
I downloaded this and it froze my VB. I had to restart...

Using a control array of 50+ pictureboxes is not the most memorable favourable thing to do... You'd be better off learning how to use BitBlt and drawing the cards directly onto one large picturebox.

As for your question? I don't understand... It moves the cards where they are because thats where you drew them.
When you click new game, it moves them to where you tell them to go.

Pookie
03-20-2002, 06:36 PM
WeavMan, you are going about this the long and hard way.

You don't need to go to so much trouble to do what you are doing.

First of all, it would have been better to have all the pictureboxes under one name, from 1-52 instead of 4 seperate pbox arrays.

Then at the start, you would have a check and storage arrays.
Make all the Cardused() array to false:

for n=1 to 52
do
card=int(rnd*51)+1
loop until CardUsed(card)=false
CardUsed(card)=true
Storage(card)=n
next


Now you have all the cards randomly mixed up.

Count=1
For x=0 to 6
For y=1 to 2+x
With PicCards(Count)
.left=x*1000+100
.Top=y*250+100
.zOrder(0)
.Refresh
End With
Count=Count+1
Next y
Next x

Now Count will be a pointer to the next card on the pile.

Only problem here is the cards under the front cards ain't suppose to be shown. :D But that's another story.

Anyway this is a start to help you out with it....

trevland06
03-22-2002, 04:42 AM
Try using Cards32.Dll or something. Check out Lucky's VB... I found a tutorial there. (didnt do it cause i just wanted to read. not realy make one,. lol)

Cwsoccer20
03-22-2002, 09:06 AM
How bout some just straight code for this game?

Cwsoccer20
03-25-2002, 08:34 AM
When i used pookie's code i have got a subscript error on my array.why would this happen? and what is CARDUSED()?

ChiefRedBull
03-25-2002, 08:38 AM
A subscript out of range is when you try to access an element of an array that doesn't exist. For example, if I had an array:Dim myArray(1 To 5) As String

myArray(6) = "boo!" ' this would cause an error, because array element 6 doesn't exist

I'm not quite sure about pookies code, but I am sure that he will explain it for you....

Pookie
03-25-2002, 08:47 PM
Sorry about confusing you a bit there with the code, it wasn't code which you could just stick into your program but was to show you a better way of making the solitaire game.


Dim Storage(52) as long ' you put this at the start
' of the form (or module) Don't put it in the sub itself

Dim CardsUsed(52) as boolean ' this goes in the sub
Dim Card as long ' temp info variable
Dim n as long ' temp loop variable

For n=1 to 52
Do
Card=Int(Rnd * 52) + 1
Loop Until CardUsed(Card) = False
CardUsed(card) = True
Storage(card) = n
next

Cardsused() as a temp Array just so that you can randomly set up the pack of cards.
Storage() is the array which the cards will be stored in.
So Storage(1) will be the first card in the pack to be drawn from...

This 2nd routine is the code which shows you how to move all the cards into the correct spots.
Though as people have said before, you should put all the cards into one picturebox and bitblt them onto the screen as you need to hide all the cards under the top card so the person can't see them.

Count=1
For x=0 to 6
For y=1 to 2+x
With PicCards( Storage( Count ) )
.left=x*1000+100
.Top=y*250+100
.zOrder(0)
.Refresh
End With
Count=Count+1
Next y
Next x


I won't write the code to hide the cards as you would need a single picturebox with all the cards in it as well as an added card facing down into it which would be used as the hidden card...

How is the card game going btw?

chrgibson
03-26-2002, 02:28 AM
Hi, in regards to shuffling the cards.
I wrote scrabble and although i didnt use this technique i should have : )

Create a String variable to hold the cards in the pack.
Create a for next loop which puts numbers 1 to 52 in the string.
You'll have to put 0102030405 etc... so they all have 2 digits.

Then when you want to pick a card, get a random number between 1 and Len(CardStr) and use this to pick the card out using Mid.

Rebuild the string (using Left and Right) excluding this card.
This will mean that it always picks the card first time.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum