Re: (IRV's reponse)Help With My Game of Black Jack

new topic     » topic index » view thread      » older message » newer message

David Roach wrote:

> This below is what loads the card images right?
> When I run this I get some errors. Like "deck has
> not been declared. Would I declare that as an object
> or an atom?

It's a sequence, since it will ultimately look like this at the end of this
loop:

   { "1.bmp", "2.bmp", "3.bmp" ... "52.bmp" }

> Forget the actual game for now. How would I
> take the loaded images and display them clicking
> on the "Hit Me" button.

OK, I know I should have pre-tested this, so here's the caveat:

   UNTESTED CODE!

I'm assuming you are using Win32Lib. Let's take a simple example. Here's
code to load a bitmap called "card.bmp" and store the handle in the atom
theBitmap. Note that handles are 32 bit values, so they are stored in atoms.
Integers "only" hold 31 bits of data:

   -- handle to a bitmap
   atom theBitmap

   -- load a card image
   theBitmap = loadBitmapFromFile( "CARD.BMP" )

I'll assume that you have a window called TheWindow and a button called
TheButton. When TheButton is clicked, you want to draw TheBitmap. Here's the
code that does the trick:

   procedure onClick_TheButton()

      -- draw theBitmap in TheWindow at (1,1)
      drawBitmap( TheWindow, theBitmap, 1, 1 )

   end procedure

Now the procedure has to be attached to TheButton's onClick routine:

   onClick[TheButton] = routine_id("onClick_TheButton")


So when you click the button, the bitmap stored in CARD.BMP should appear.
If it doesn't

OK, on to a more complex example.

Assuming that the card files are called "CARD1.BMP" through "CARD52.BMP", we
can load them into TheDeck as follows:

   -- holds the handles to the card bitmaps
   sequence theDeck, fileName

   -- make theDeck empty
   theDeck = {}

   for i = 1 to 52 do

      -- build the file name
      fileName = sprintf( "CARD%d", {i} )

      -- append the bitmap handle to the list
      theDeck &= loadBitmapFromFile( fileName )

   end for

Here's the new routine for the button. When it's clicked, a random card will
be placed in TheWindow:

   procedure onClick_TheButton()

      -- draw a random bitmap from theDeck in TheWindow at (1,1)
      integer pick
      atom hBitmap

      -- pick a card at random
      pick = rand( 52 )

      -- get the bitmap handle from theDeck
      hBitmap = theDeck[ pick ]

      -- draw the bitmap in TheWindow at (1,1)
      drawBitmap( TheWindow, hBitmap, 1, 1 )

   end procedure

Once again, the routine needs to be attached to TheButton's onClick routine:

   onClick[TheButton] = routine_id("onClick_TheButton")

Hope this helps!

-- David Cuny

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu