Playing cards: Difference between revisions

Content added Content deleted
Line 1,116: Line 1,116:
Structure _membersDeckClass
Structure _membersDeckClass
*vtable.i
*vtable.i
Size.i ;# of cards present
size.i ;zero based count of cards present
cards.card[#MaxCards] ;deck content
cards.card[#MaxCards] ;deck content
EndStructure
EndStructure


Interface DeckObject
Interface deckObject
Init()
Init()
shuffle()
shuffle()
Line 1,132: Line 1,132:
Static suits.s = "Diamonds Clubs Hearts Spades"
Static suits.s = "Diamonds Clubs Hearts Spades"
Protected c.s
Protected c.s
If isAbbr
If isAbbr
Line 1,157: Line 1,156:
;isAbbr is #True if the card dealt is abbrieviated to 2 characters
;isAbbr is #True if the card dealt is abbrieviated to 2 characters
Protected c.card
Protected c.card
If *this\size < 0
;deck is empty
c = *this\cards[*this\Size]
ProcedureReturn ""
*this\Size - 1
Else
ProcedureReturn _formatCardInfo(@c, isAbbr)
c = *this\cards[*this\size]
*this\size - 1
ProcedureReturn _formatCardInfo(@c, isAbbr)
EndIf
EndProcedure
EndProcedure


Line 1,167: Line 1,170:
Protected i
Protected i
For i = 0 To *this\Size
For i = 0 To *this\size
Print(_formatCardInfo(@*this\cards[i], isAbbr))
Print(_formatCardInfo(@*this\cards[i], isAbbr))
If i <> *this\Size: Print(", "): EndIf
If i <> *this\size: Print(", "): EndIf
Next
Next
PrintN("")
PrintN("")
Line 1,177: Line 1,180:
;works with decks of any size
;works with decks of any size
Protected w, i
Protected w, i
Dim shuffled.card(*this\Size)
Dim shuffled.card(*this\size)
For i = *this\Size To 0 Step -1
For i = *this\size To 0 Step -1
w = Random(i)
w = Random(i)
shuffled(i) = *this\cards[w]
shuffled(i) = *this\cards[w]
Line 1,188: Line 1,191:
Next
Next
For i = 0 To *this\Size
For i = 0 To *this\size
*this\cards[i] = shuffled(i)
*this\cards[i] = shuffled(i)
Next
Next
Line 1,197: Line 1,200:
If *newDeck
If *newDeck
*newDeck\vtable = ?vTable_deckClass
*newDeck\vtable = ?vTable_deckClass
*newDeck\Size = #MaxCards - 1
*newDeck\size = #MaxCards - 1
setInitialValues(*newDeck)
setInitialValues(*newDeck)
EndIf
EndIf
Line 1,219: Line 1,222:
OpenConsole()
OpenConsole()


Define deck.DeckObject = newDeck()
Define deck.deckObject = newDeck()
Define deck2.DeckObject = newDeck()
Define deck2.deckObject = newDeck()


If deck = 0 Or deck2 = 0
If deck = 0 Or deck2 = 0