+n_cards = (count) ->
+ return "#{count} cards" unless count is 1
+ return "1 card"
+
+initialize_cards = () ->
+ # clear everything
+ $('.card').remove()
+ $('.blank_card').remove()
+
+ # instantiate cards in play
+ for card in state.cards
+ instantiate_card card unless card.pile
+
+ # build piles
+ piles = [
+ {key: 'p2_draw', x: transform_x(160), y: transform_y(20), name: "Draw Pile"}
+ {key: 'p2_discard', x: transform_x(20), y: transform_y(20), name: "Discard Pile"}
+ {key: 'p1_draw', x: transform_x(160), y: transform_y(flip_y(20)), name: "Draw Pile"}
+ {key: 'p1_discard', x: transform_x(20), y: transform_y(flip_y(20)), name: "Discard Pile"}
+ ]
+ for pile in piles
+ pile.$blank = new_blank_card pile.x, pile.y
+ count = 0
+ top = null
+ if state.piles[pile.key]?.length
+ count = state.piles[pile.key].length
+ top = state.piles[pile.key][0]
+ $caption = $ $ "<div class=\"pile_caption\"><div>#{pile.name}:</div><div class=\"n_cards\">#{n_cards count}</div></div>"
+ pile.$caption = $caption
+ if top?
+ top.x = pile.x
+ top.y = pile.y
+ instantiate_card top
+ top = top.view
+ else
+ top = pile.$blank
+
+ top.append $caption
+
+ #pile.drag_handler = top.bind 'dragstart', ->
+ # FIXME
+
+