
Object subclass: #CardDeck
  instanceVariableNames: 
    'theCards '
  classVariableNames: ''
  poolDictionaries: ''  !


!CardDeck class methods !

newDeck
        "comment"
    | init |
    init := CardDeck new.
    init cards.
^init! !



!CardDeck methods !
   
cards
        "Skapar ett kort av varje sort."
    | list1 list2 |
    theCards := OrderedCollection new: 52.

    1 to: 4 do: [ :s |
        1 to: 13 do: [ :i | theCards addLast: (Card suit: s rank: i) ].
    ].!

isEmpty
      "returns true if Deck is empty"
    | status |

    theCards size > 0
    ifTrue:   [status := false]
    ifFalse: [status := true].
^status!
  
next
        "Draws a card from the deck"
    | drawnCard |

    drawnCard := theCards at: 1.
    theCards removeFirst.

^drawnCard!
 
shuffle
        "Blandar leken"
    | n1 n2 temp1 temp2 |

    Random setFroTime.
    1 to: 1000 do: [ :i |
    n1 := (Random next: ((theCards size) - 1)) + 1.
    n2 := (Random next: ((theCards size) - 1)) + 1.

    temp1 := theCards at: n1.
    temp2 := theCards at: n2.
    theCards at: n1 put: temp2.
    theCards at: n2 put: temp1.
    ].

^(theCards size)! !
