1. Re: Help With My Game of Black Jack

On Wed, 01 Dec 1999, you wrote:

> Hey this is good but how do I do this and associate the shuffled deck to
> actual bitmaps. So when I click on "Hit Me" a card is shown at a designated
> place in my window, and more importantly, so when "Hit Me" is clicked again
> the next card is shown just to the side of the first card. Thanks again for
> your responces.

You have 52 bitmaps? If so, you can either put the names of the bitmaps in a
list, like so:
object deck
 deck =
and use the routine below to shuffle and draw, then load the appropriate bmp
with read_bitmap()  file and display it using display_image().

A much faster way would be to load the actual bitmaps into the deck, instead of
the file names.
object image
deck = {}
image = read_bitmap("AceofSpades.bmp")
deck = append(deck,image[2])
image = read_bitmap("AceofDiamonds.bmp")
deck = append(deck,image[2])

As you can see, that gets to be a lot of code. If you re-name your card pix
with numbers, then you can write a loop to load everything in 5 lines:

deck = {}
for card = 1 to 52 do -- cards images will be in 1.bmp, 2,bmp, 3.bmp.....
 image = read_bitmap(sprintf("%d.bmp",card))
 deck = append(deck,image[2]) -- throw away the palette info.
end for

-----------------------------------------------------
-- function draw returns a hand of <<count>> cards
-----------------------------------------------------
function draw(integer count)
object hand
hand = {} -- empty
for i = 1 to count do      -- however many cards were requested
    x = rand(length(deck)) -- pick a card at random from remaining deck
    hand = append(hand, deck[x]) -- add that card to your hand
    deck = deck[1..x-1] & deck[x+1..length(deck)] -- and remove from deck
    if length(deck) < 1 then exit -- no more cards
    end if
end for
return hand
end function

--begin untested code
procedure Show(object hand) -- stacks card images, last drawn on top
sequence coords
coords = {10,10}
for i = 1 to length(hand) do
  display_image( {coords}, hand[i])
  coords += {20,20} -- next card shows down and to the right by 20 pixels
end for
end procedure
-------------------------------------------
-- Test stub
-------------------------------------------
deck = draw(52) -- shuffle

myhand = draw(1)
Show(myhand)
-- do some other stuff, like get user input

myhand = append(myhand,draw(1)) -- adds 1 card to the hand, and displays
Show(myhand)

Hope this helps
Irv

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu