Playing cards: Difference between revisions

Line 1,116:
Structure _membersDeckClass
*vtable.i
Sizesize.i ;#zero based count of cards present
cards.card[#MaxCards] ;deck content
EndStructure
 
Interface DeckObjectdeckObject
Init()
shuffle()
Line 1,132:
Static suits.s = "Diamonds Clubs Hearts Spades"
Protected c.s
If isAbbr
Line 1,157 ⟶ 1,156:
;isAbbr is #True if the card dealt is abbrieviated to 2 characters
Protected c.card
If *this\Sizesize -< 10
;deck is empty
c = *this\cards[*this\Size]
ProcedureReturn ""
*this\Size - 1
Else
ProcedureReturn _formatCardInfo(@c, isAbbr)
c = *this\cards[*this\Sizesize]
*this\size - 1
ProcedureReturn _formatCardInfo(@c, isAbbr)
EndIf
EndProcedure
 
Line 1,167 ⟶ 1,170:
Protected i
For i = 0 To *this\Sizesize
Print(_formatCardInfo(@*this\cards[i], isAbbr))
If i <> *this\Sizesize: Print(", "): EndIf
Next
PrintN("")
Line 1,177 ⟶ 1,180:
;works with decks of any size
Protected w, i
Dim shuffled.card(*this\Sizesize)
For i = *this\Sizesize To 0 Step -1
w = Random(i)
shuffled(i) = *this\cards[w]
Line 1,188 ⟶ 1,191:
Next
For i = 0 To *this\Sizesize
*this\cards[i] = shuffled(i)
Next
Line 1,197 ⟶ 1,200:
If *newDeck
*newDeck\vtable = ?vTable_deckClass
*newDeck\Sizesize = #MaxCards - 1
setInitialValues(*newDeck)
EndIf
Line 1,219 ⟶ 1,222:
OpenConsole()
 
Define deck.DeckObjectdeckObject = newDeck()
Define deck2.DeckObjectdeckObject = newDeck()
 
If deck = 0 Or deck2 = 0
Anonymous user