Anonymous user
Playing cards: Difference between revisions
Slightly improve Smalltalk version 2
(Add a second solution in Smalltalk) |
(Slightly improve Smalltalk version 2) |
||
Line 5,400:
===Version 2===
{{works with|GNU Smalltalk}}
<lang smalltalk>Object subclass: Deck [
| cards |
Line 5,411 ⟶ 5,410:
initializeWith: aCardClass
[cards :=
displayOn: aStream
Line 5,430 ⟶ 5,429:
Object subclass: Card [
Card class >>
[^#(
'2d' '3d' '4d' '5d' '6d' '7d' '8d' '9d' 'Td' 'Jd' 'Qd' 'Kd' 'Ad'
Line 5,436 ⟶ 5,435:
'2h' '3h' '4h' '5h' '6h' '7h' '8h' '9h' 'Th' 'Jh' 'Qh' 'Kh' 'Ah'
'2c' '3c' '4c' '5c' '6c' '7c' '8c' '9c' 'Tc' 'Jc' 'Qc' 'Kc' 'Ac'
) deepCopy]
]</lang>▼
▲</lang>
The Card class should obviously be more intricate to fulfil the needs of a CardGame class. :-)
Use example:
<lang Smalltalk>st> myDeck := Deck of: Card
a Deck
st> myDeck
st> myDeck shuffle
a Deck
st> myDeck
st> myHand := OrderedCollection new
OrderedCollection ()
Line 5,457 ⟶ 5,454:
5
st> myHand
OrderedCollection ('Ad' 'Jd' 'Ks' 'Th' '6d' )</lang>
=={{header|Swift}}==
|