|
-
Mar 6th, 2002, 03:47 PM
#1
Thread Starter
Lively Member
declaring ace as 1 or 11?
can anyone tell me how i declare a ace as 1 0r 11 in a blackjack game im writing , and where i put it
thanks
-
Mar 6th, 2002, 04:07 PM
#2
PowerPoster
I wouldnt think u would need to 'declare' it anywhere. it is just a programming issue. ie Say the player has A,2,5 you would display 8 and 18. If the next card dealt is a 5 then you would only display 13. Ie U test the deck for the number of Aces and provide the option of adding ten where the total is less than 21.
-
Mar 6th, 2002, 04:26 PM
#3
Thread Starter
Lively Member
hi beachbum thanks for the reply but how is that written in code
hope u dont mind me asking
this is a snippet of my code
case 4
txtCard = "Ace of Clubs"
imgComp1.Picture = imgClub.Picture
lblComp1.Caption = "A"
End Select
txtValue = 1
txtTotal = txtTotal + 1
tink
-
Mar 6th, 2002, 04:35 PM
#4
PowerPoster
Again it is a programming issue. Personally, I wouldnt record increment the total as you go along and would rather keep the cards in an array and total them each time providing the player with results for both 1 and 11 if appropriate.
Also, you will have to handle splits etc. So it is not as simple as incrementing the total. I'm not gonna put code here becos it is all dependent on how you've done it already and your knowledge of dynamic arrays.
So here is pseudo code
Cards(0) = 5
Cards(1) = 1 'Ace
Create a simple function to add all Cards regardless of size of array.. eg For x = 0 to Ubound(Cards).....
Display 6 and 16 to player
If user selects a new card then resize the array preserving original cards.
Redim Preserve Cards(x) where x is the new count ie 2 in this instance
Cards(2) = 7
Again you add to a total and get 13 and 23 but since 23 is above 21 only display the 13.
hope this gives u some ideas
-
Mar 7th, 2002, 08:39 AM
#5
Addicted Member
Dynamically reassigning the array is a waste of time as thye max you can have is 5 cards x hands (for spilts)
But you could dynamically array hands for example
Code:
Type Cards
public Cards(5) as integer
end type
Dim hands() as cards
redim hands(1)
then:
Hands(1).cards(1) = 1
Hands(1).cards(2) = 9
if a spilt happens
redim preverse hands(ubound(hands) +1)
then
hands(newhand).cards(1) = hands(spilthand).cards(2)
hands(spilthand).cards(2) = 0
As for Adding them up
dim i as integer
dim isAce as boolean
dim total as integer
for i = 1 to 5
if hands(currenthand).cards(i) = 1 then
isAce = true
total = total + 11
end if
total = total + hands(currenthand).cards(i)
next
if total > 21 and isAce = true then
total = total -10
end if
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
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
|