JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
shuffling, started on state structure
authorJason Woofenden <jason@jasonwoof.com>
Mon, 24 Oct 2011 01:06:06 +0000 (21:06 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 24 Oct 2011 01:06:06 +0000 (21:06 -0400)
client.coffee
style.less

index 61643b0..a87cb54 100644 (file)
@@ -1,16 +1,55 @@
 $table = null
 
+state = {
+       card_types: [
+               {text: "Rusty Camel"}
+               {text: "Angry Ocelot"}
+               {text: "Unruly Parsnip"}
+       ],
+       # values are indexes into card_types array
+       my_cards: [0, 0, 0, 1, 1, 2],
+       your_cards: [0, 1, 1, 2, 2, 2],
+       auto_shuffle: true
+}
+
+unless Array::shuffle?
+       Array::shuffle = ->
+               return if @length is 0
+               top = @length
+
+               while --top
+                       current = Math.floor(Math.random() * (top + 1))
+                       tmp = @[current]
+                       @[current] = @[top]
+                       @[top] = tmp
+               return
+
 add_card = (text, x, y) ->
-       card = $ $ "<div class=\"card\" style=\"left: #{x}px; top: #{y}px\">#{text}</div>"
+       card = $ $ "<div class=\"card\" style=\"left: #{x}px; top: #{y}px\">#{text}<br><span>&nbsp;</span></div>"
        $table.append card
        card.draggable()
+       card.bind 'dragstop', (event, ui) ->
+               p = card.position()
+               card.children().html("(#{p.left}, #{p.top})")
+               # FIXME tell server
        
 init = ->
-       $table = $ '#table'
-       add_card "card 1", 100, 20
-       add_card "two", 250, 20
-       add_card "third card", 290, 50
+       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
+       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
 
 $ ->
+       $table = $ '#table'
        init()
 
index 91ce8bc..e0899b0 100644 (file)
@@ -23,8 +23,8 @@ h1 {
 }
 
 #table {
-       height: 600px;
-       width: 860px;
+       height: 700px;
+       width: 960px;
        background: #eee;
        position: relative;
        .shadow(2px, 2px, 10px, 0.4);