 class User extends Backbone.Model
 
 
+
 class UserCollection extends Backbone.Collection
   model: User
 
+
 users = new UserCollection()
+
+
 
 
 

    socket.emit('LobbyList', users.toJSON())

  socket.on 'StateUpdate', (data) ->
    me.set('state', data)
    if me.opponent
      me.opponent.socket.emit 'StateUpdate', me.toJSON().state

    # send my state to the other player if I'm in a game
    #socket.broadcast.emit 'StateUpdate', user.toJSON()

  socket.on 'disconnect', ->
    if me.opponent
      me.opponent.playing = false
      me.opponent.socket.emit 'YourOpponentLeftSorryBro', me.toJSON()

    users.remove(me)
    socket.broadcast.emit 'LobbyList', users.toJSON()

  # Create a game if there are two users free
  users.forEach (u) ->
    if u != me and !u.opponent

      u.opponent = me
      me.opponent = u
      u.set('playing', me.get('nick'))
      me.set('playing', u.get('nick'))

      me.socket.emit('StartGame', {opponent: u})
      u.socket.emit('StartGame', {opponent: me})
