home *** CD-ROM | disk | FTP | other *** search
- property _cards
-
- on new me
- me._create()
- return me
- end
-
- on _create me
- unshuffledCards = []
- repeat with theRank in [#ace, #two, #three, #four, #five, #six, #seven, #eight, #nine, #ten, #jack, #queen, #king]
- repeat with theSuit in [#hearts, #diamonds, #clubs, #spades]
- unshuffledCards.add(new(script("playing cards"), theRank, theSuit))
- end repeat
- end repeat
- _cards = me._shuffle(unshuffledCards)
- end
-
- on _shuffle me, unshuffledCards
- shuffledCards = []
- repeat while unshuffledCards.count > 0
- randomCard = unshuffledCards[random(unshuffledCards.count)]
- shuffledCards.add(randomCard)
- unshuffledCards.deleteOne(randomCard)
- end repeat
- return shuffledCards
- end
-
- on mDeal me, totalCycles
- if totalCycles > 1 then
- theHand = []
- repeat with cycleNum = 1 to totalCycles
- theHand.add(me._DrawCard())
- end repeat
- return theHand
- else
- return me._DrawCard()
- end if
- end
-
- on _DrawCard me
- cardDrawn = me._cards[1]
- me._deleteCard(cardDrawn)
- if not me._getCardCount(0) then
- me._create()
- end if
- return cardDrawn
- end
-
- on _deleteCard me, cardToDelete
- _cards.deleteOne(cardToDelete)
- end
-
- on _getCardCount me, minAmount
- if _cards.count > minAmount then
- return 1
- else
- return 0
- end if
- end
-