Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Director MX Bugs: editable text and on prepareFrame
PRegEx
Composite Xtra
Sub Hunt
MPEG Xtra Controller Button
bubbleSortForStrings AND bubbleSortForStringLists
Show Time
Progress Bar
Get Line Number of Word
DataSafe Xtra for Authorware and Director
 

 

 

Behavior Card Shuffler

Added on 10/11/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

This is a basic card shuffler routing. You will need to name your cards by suit and by number, starting with 2 and going to 14, like so... 1-2,1-3,1-4,1-5, etc. up to 4-14 Also have the back of the card graphic named 0-0 This does not have any AI as it is just the shuffling and swapping routine. For more detailed examples and explination check out the article in the "How do I...?" section.

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)

property spriteNum, suit, cardNum, player

global cardList, masterList, activeList, flipList, swap

on getPropertyDescriptionList me
  p_list= [:]
  p_list.addProp(#player, [#format : #string, #default : "Human", #comment : "Which Player:", #range : ["Human", "Computer"]])
  return p_list
end

on beginSprite me
  if masterList = void then
    masterList = []
    --create master list of cards
    repeat with x = 1 to 4
      --add each card
      repeat with y = 2 to 14
        masterList.add(x & "-" & y)
      end repeat
    end repeat
  end if
  if cardList = void then cardList = duplicate(masterList)
  if activeList = void then activeList = []
  shuffle()
end

on shuffle me
  if activeList.getOne(spriteNum) <> 0 then
    --old game list, reset the list
    cardList = duplicate(masterList)
    activeList = []
  end if
  --set a card
  getCard()
  activeList.add(spriteNum)
  if flipList <> [] then flipList = []
  swap = true
end
on mouseUp me
  if flipList = void then flipList = []
  if player = "Human" and swap = true then
    if flipList.getOne(spriteNum) = 0 then
      flipList.add(spriteNum)
      sprite(spriteNum).member = "0-0"
    else
      flipList.deleteOne(spriteNum)
      sprite(spriteNum).member = member(suit & "-" & cardNum)
    end if
  end if
end

on changeCards me
  if flipList.getOne(spriteNum) <> 0 then
    --change the card
    getCard()
    flipList.deleteOne(spriteNum)
  end if
  swap= false
end

on getCard me
  the itemDelimiter = "-"
  whichCard = random(cardList.count)
  suit = cardList[whichCard].item[1]
  cardNum = cardList[whichCard].item[2]
  cardList.deleteAt(whichCard)
  if player = "Human" then
    sprite(spriteNum).member = member(suit & "-" & cardNum)
  else
    sprite(spriteNum).member = member("0-0")
  end if
end

on showCards me
  sprite(spriteNum).member = member(suit & "-" & cardNum)
  swap= false
end

on getBehaviorDescription me
  return "This is a card shuffler, swapper, and basic controller. Add your own AI for any basic card game."
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail