|
-
Dec 7th, 2011, 09:06 PM
#1
Thread Starter
New Member
Hold'em
I've a made a Texas Hold'em game but am having a little trouble. I have it dealing random cards from the deck, however I'm not sure how to stop it from dealing the same card twice.
(Here's what I have. s1, s2, s3 are the card images)
Code:
Dim x As Integer
Dim card(52) As Object
Dim x, y, z As Integer
Randomize()
card(0) = My.Resources.s1
card(1) = My.Resources.s2
card(2) = My.Resources.s3
card(3) = My.Resources.s4
card(4) = My.Resources.s5
For x = 0 To 51 * Rnd() Step 1
piccard1.Image = card(x)
Next
For y = 0 To 51 * Rnd() Step 2
piccard2.Image = card(y)
Next
For z = 0 To 51 * Rnd() Step 3
picflop1.Image = card(z)
Next
Like I said, this works but it will deal the same card. Although I like having pocket aces, I perfer they not be the same suit.
I'm sure it's something simple, but I'm fairly new to VB. Any input would be appreciated.
[Code tags added by moderator]
-
Dec 9th, 2011, 07:50 AM
#2
PowerPoster
Re: Hold'em
 Originally Posted by Starke
I've a made a Texas Hold'em game but am having a little trouble. I have it dealing random cards from the deck, however I'm not sure how to stop it from dealing the same card twice.
(Here's what I have. s1, s2, s3 are the card images)
Code:
Dim x As Integer
Dim card(52) As Object
Dim x, y, z As Integer
Randomize()
card(0) = My.Resources.s1
card(1) = My.Resources.s2
card(2) = My.Resources.s3
card(3) = My.Resources.s4
card(4) = My.Resources.s5
For x = 0 To 51 * Rnd() Step 1
piccard1.Image = card(x)
Next
For y = 0 To 51 * Rnd() Step 2
piccard2.Image = card(y)
Next
For z = 0 To 51 * Rnd() Step 3
picflop1.Image = card(z)
Next
Like I said, this works but it will deal the same card. Although I like having pocket aces, I perfer they not be the same suit.
I'm sure it's something simple, but I'm fairly new to VB. Any input would be appreciated.
[Code tags added by moderator]
i think the problem is how you use the rnd() function.
heres something that maybe can help you(at least i hope ):
Code:
Function Random(Lowerbound As Long, Upperbound As Long)
Randomize
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
-
Dec 9th, 2011, 09:34 PM
#3
Re: Hold'em
Heres a program I whipped up that'll shuffle the cards. Should be easy enough for ya to understand.
vb Code:
Option Explicit Dim Card_Number(1 To 52) As Integer Dim Deck(1 To 52) As String Private Sub Setup_Deck() Deck(1) = "A-S" Deck(2) = "2-S" Deck(3) = "3-S" Deck(4) = "4-S" Deck(5) = "5-S" Deck(6) = "6-S" Deck(7) = "7-S" Deck(8) = "8-S" Deck(9) = "9-S" Deck(10) = "10-S" Deck(11) = "J-S" Deck(12) = "Q-S" Deck(13) = "K-S" Deck(14) = "A-C" Deck(15) = "2-C" Deck(16) = "3-C" Deck(17) = "4-C" Deck(18) = "5-C" Deck(19) = "6-C" Deck(20) = "7-C" Deck(21) = "8-C" Deck(22) = "9-C" Deck(23) = "10-C" Deck(24) = "J-C" Deck(25) = "Q-C" Deck(26) = "K-C" Deck(27) = "A-D" Deck(28) = "2-D" Deck(29) = "3-D" Deck(30) = "4-D" Deck(31) = "5-D" Deck(32) = "6-D" Deck(33) = "7-D" Deck(34) = "8-D" Deck(35) = "9-D" Deck(36) = "10-D" Deck(37) = "J-D" Deck(38) = "Q-D" Deck(39) = "K-D" Deck(40) = "A-H" Deck(41) = "2-H" Deck(42) = "3-H" Deck(43) = "4-H" Deck(44) = "5-H" Deck(45) = "6-H" Deck(46) = "7-H" Deck(47) = "8-H" Deck(48) = "9-H" Deck(49) = "10-H" Deck(50) = "J-H" Deck(51) = "Q-H" Deck(52) = "K-H" End Sub Private Sub ShuffleCard_Number() Dim CardCount As Integer 'This will be my loop counter Dim CardVal As Integer 'This will get assigned the random value CardCount = 1 'Resets card count to 1 Do While CardCount < 53 'This sets every slot in Card_Number to -1 Card_Number(CardCount) = -1 'so that later I can tell if the slot is empty CardCount = CardCount + 1 'or not Loop CardCount = 1 'Resets card count to 1 Do While CardCount < 53 'Loop until every slot is full 10 CardVal = Int((52 * Rnd) + 1) 'Set CardVal = to a random number If Card_Number(CardVal) = -1 Then 'Take random slot and see if there is a card 'in it yet. If there isn't it will be = to -1 'if there is it will be equal to a different 'value. Card_Number(CardVal) = CardCount 'There isn't so put current card in that slot CardCount = CardCount + 1 'Increment my card count Else: GoTo 10 'There is so start again from the beginning End If Loop 'Do it all again if < 53 End Sub Private Sub Command1_Click() Me.Cls ShuffleCard_Number Print Deck(Card_Number(1)), Deck(Card_Number(2)), Deck(Card_Number(3)), Deck(Card_Number(4)), Deck(Card_Number(5)) End Sub Private Sub Form_Load() Me.Show Me.AutoRedraw = True Randomize Setup_Deck End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|