Two of a kind? (card game)

Zincdust
12-07-2004, 10:06 PM
Hey gang,
I am trying to throw together a card game based on code that I had read on here earlier (see this thread: http://www.xtremevbtalk.net/showthread.php?t=48147 ), and I was wondering what could we add to the code given in message #6 to get it to recognize two cards of the same value shown in the list box? Any help would be greatly appreciated!! Thanks a million in advance!

Regards,
-Zinc

wayneph
12-08-2004, 06:51 AM
Hey gang,
I am trying to throw together a card game based on code that I had read on here earlier (see this thread: http://www.xtremevbtalk.net/showthread.php?t=48147 ), and I was wondering what could we add to the code given in message #6 to get it to recognize two cards of the same value shown in the list box? Any help would be greatly appreciated!! Thanks a million in advance!

Regards,
-Zinc

It looks like it's already in there. There were also a couple suggestions further down in the thread as other ways to make sure there are no duplicates. Is that what you mean? Also note that the post had VB6 code, and some of the funtions come from different classes in .NET.

Zincdust
12-08-2004, 09:46 AM
Yeah, I saw that it had a suggestion for no duplicate cards, but what I am thinking of is if you had an Ace of Spades and an Ace of Diamonds, a message box would pop up saying "You have a pair!", whereas if you had a six, a two, a nine, a Jack and a King, a message box would say "You do not have a pair." Something along those lines. Thanks!

Also, I forgot to mention that I had converted it to .Net code.

wayneph
12-08-2004, 10:15 AM
You can use a similar loop to the one that exists. I haven't tested this code so there may be a syntax error but it should be close.



checkCard = 0
pairFound = false

While checkCard < List1.Count -1 And not pairFound
'This will look at cards 1-4 and compare it to all cards above it
For cardLoop = checkCard +1 To List1.Count -1
'This will loop from the current card to the end
If List1.Item(cardLoop).Value.Substring(0,1) = _
List1.Item(checkCard).Value.Substring(0,1) Then
'If the first character of the value matches then it's the same card
'based on AHe = Ace of Heards and ASp = Ace of Spades
pairFound = true
Exit For
End If
Next
End While

'This just checks to see if there is a pair. It doesn't check for more than one,
'or look at what it is a pair of...
If pairFound Then
'Do something for True
Else
'Do something for not true
End If

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum