Re: Assigning values to bitmaps in a sequence :)

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

On Thu, 02 Dec 1999, you wrote:
> Hello all,
> This stuff is finally starting to make since to me. Just a little problem.
> I am working on my first program, Black Jack. I have 52 bitmaps named
> "1-52.bmp". These are loaded into a sequence Deck. Now how do assign values
> to the elements in Deck. Lets say the ace of hearts is loaded into
> Deck[1] how do I assign it a value of 1 and still keep the bitmap loaded
> into that element. Or would I use another element like Deck[2] for the
> value of the card. Basicaly I need to have a value associated with a Bitmap
> in a sequence. Any help would be greatly apriciated.

You'll need to keep track of each card's suit as well as its face value.
This is best done with a structure. You can simulate a structure as follows:

constant BMP_ERR = -- stuff to help when loading files
{"Cannot open %d.bmp","Unexpected EOF in%d.bmp","Unsupported format in %d.bmp"}

-- our deck of cards "structure" looks like this:
     constant VALUE = 1, SUIT = 2, GRAPH = 3,
                 HEARTS = 1, DIAMONDS = 2,  SPADES = 3, CLUBS = 4,
                 ACE = 1, JACK = 11, QUEEN = 12, KING = 13

   object cardrec
         cardrec = { 0, 0, {} } -- storage for value, suit,  and graphic data
   object deck
          deck = repeat(cardrec ,52) -- 52 instances of cardrec
-- end structure

-- Now, load the card values and the actual bitmap (not the bmp. filename)
-- into the deck.

object temp -- must be object
integer count

count = 1
for suit =  HEARTS to CLUBS do
 for card = ACE to KING do
  temp = read_bitmap(sprintf("%d.bmp", count )) -- read and store the bitmap
  -- if that doesn't work try: sprintf("\"%d.bmp\"",count)

  if atom(temp) then                               -- error reading file
     sprintf (1, BMP_ERR[temp],  count )   -- display a diagnostic msg

  else                                                 -- store the card data
    deck[count] [VALUE] = card
    deck[count] [SUIT]     = suit
    deck[count] [GRAPH] = temp[2]         -- discard the palette
  end if

 count += 1
 end for -- card
end for -- suit

Don't bother storing multiple values for the Ace, or other cards, that can
be handled within your  scoring logic. ( if card[VALUE] = ACE then count it as
either 1 or 11 whichever is better)

Regards,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu