- if state.auto_shuffle
- state.my_cards.shuffle()
- state.your_cards.shuffle() # FIXME have the server or other player do this
- state.auto_shuffle = false
- # FIXME tell server
- left = 15
- top = 450
- for card in state.my_cards
- add_card state.card_types[card].text, left, top
- left += 120
- left = 15
- top = 250
- for card in state.your_cards
- add_card state.card_types[card].text, left, top
- left += 120
+ if window.location.hash? and window.location.hash.length > 0
+ me = window.location.hash.substr 1
+ winloc = "#{window.location}"
+ server_url = winloc.substr 0, winloc.length - window.location.hash.length
+ else
+ me = 'p1'
+ server_url = window.location
+
+ state = window.game_model.new me
+ state.on 'move', (agent, card, x, y) ->
+ # FIXME add/handle pile argument
+ if agent is me
+ tell_server ['move', agent, card, x, y]
+ else
+ state.cards[card].view.animate { left: "#{x}px", top: "#{y}px"}, 800
+ state.on 'mark', (agent, card, state) ->
+ @cards[card].view.toggleClass 'marked', state
+ if agent is me
+ tell_server ['mark', agent, card, state]
+ state.on 'flip', (agent, card, state) ->
+ @cards[card].view.toggleClass 'flipped', state
+ if agent is me
+ tell_server ['flip', agent, card, state]
+ state.on 'set_cards', (agent, cards) ->
+ # FIXME add agent arg and tell server if it's not us
+ $('.card').remove()
+ for card in cards
+ instantiate_card card
+ if agent is me
+ tell_server ['set_cards', agent, cards]
+
+ # timeout so browser will stop showing that we're loading
+ timeout 1, poll_for_updates