Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Match Cards game: card shuffle function...malfunction

Author
Message
Gyrich
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Here, obviously.
Posted: 13th Jan 2006 09:13
'ello. My match cards game is coming along, but I'm having a problem with the Shuffle() function. It will shuffle the data on the cards but not in the way that I want. I have the cards color coded (no textures) for the time being so I can identify which cards are which and even after shuffling the colors of the cards will have changed but the cards themselves will be in the same spot. It's hard to explain and harder to understand i suspect lol, so here's the code:



to see the phenomenon i'm talking about comment out the Shuffle() function right above the main loop (under the CardAssign() function) and run the program, you'll see that the matching works fine when you click on the cards and that the cards are in order (unshuffled). now run the program with the Shuffle() function uncommented and you'll see the colors randomly distributed, however you'll see that cards with matching colors don't match. and if you click the cards that are next to each other, you'll discover that the card values haven't moved from their original unshuffled positions(the red 2 cards are still the first 4 cards, then the green 3's...etc.) even though the colors are changed. I need to shuffle the actual values of the cards, and the colors(which will be the textures once i make them) to stay with their designated cards. Please help and thank you

DBPro User
PC: WinXP, AthlonXP 2100+ 1.7ghz, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mb DDR400 system RAM. Thank you for your help.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jan 2006 12:39 Edited at: 13th Jan 2006 12:42
I think that when you move one type to another, you have to do each variable separately. So you can't just move CardInfo, you have to move CardInfo.Ace, CardInfo.King, etc...

You could also optimise this code significantly. As you have already seen, you have to check every single card type for a match...

if Deck(FirstCard).ten = 1 and Deck(SecondCard).ten = 1...

You could save this in your cardinfo type as a single integer value from 1 to 13. Your 13 IF statements then become one...



You could even make this variable a string if it suits you. So Cardinfo.value$ could be:

1,2,3,4,5,6,7,8,9,J,Q,K,A

Same result, but it might be easier for you to get your head around.

Your CardAssign() function also reduces massively, and becomes much more easily editable...



Hope this helps...and makes sense

Gyrich
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Here, obviously.
Posted: 14th Jan 2006 00:19
LOL i KNEW there was a way to reduce those ridiculously massive functions...sheesh, thank you BatVink lol u really know your stuff.

I had to modify the code somewhat to get the card values i wanted(was getting 1 and 0 values, and there aren't 1 or 0 cards in a deck, and i wasnt getting the aces to come up either) but i was able to figure out how to get the CardAssign() function to give the values i desired, and i augmented the card coloring code a bit to have all card that were the same # be the same color. But i never would have figured it out if you hadn't given me your suggestions lol so thanx A LOT. Here's my code if you wanna run it and tell me what you think, like i said im not having any problems but perhaps there's something that will be a problem later, or just if you want to take a look:



Thaks again for your help.

DBPro User
PC: WinXP, AthlonXP 2100+ 1.7ghz, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mb DDR400 system RAM. Thank you for your help.

Login to post a reply

Server time is: 2024-09-24 13:33:44
Your offset time is: 2024-09-24 13:33:44