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 ;zero based count of cards present |
|||
cards.card[#MaxCards] ;deck content |
cards.card[#MaxCards] ;deck content |
||
EndStructure |
EndStructure |
||
Interface |
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 |
||
⚫ | |||
;deck is empty |
|||
⚫ | |||
ProcedureReturn "" |
|||
⚫ | |||
Else |
|||
⚫ | |||
⚫ | |||
*this\size - 1 |
|||
⚫ | |||
EndIf |
|||
EndProcedure |
EndProcedure |
||
Line 1,167: | Line 1,170: | ||
Protected i |
Protected i |
||
For i = 0 To *this\ |
For i = 0 To *this\size |
||
Print(_formatCardInfo(@*this\cards[i], isAbbr)) |
Print(_formatCardInfo(@*this\cards[i], isAbbr)) |
||
If i <> *this\ |
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\ |
Dim shuffled.card(*this\size) |
||
For i = *this\ |
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\ |
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\ |
*newDeck\size = #MaxCards - 1 |
||
setInitialValues(*newDeck) |
setInitialValues(*newDeck) |
||
EndIf |
EndIf |
||
Line 1,219: | Line 1,222: | ||
OpenConsole() |
OpenConsole() |
||
Define deck. |
Define deck.deckObject = newDeck() |
||
Define deck2. |
Define deck2.deckObject = newDeck() |
||
If deck = 0 Or deck2 = 0 |
If deck = 0 Or deck2 = 0 |