Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get a specific player from a table.

Works, but I don't like it.
  • Loading branch information...
commit 090492de553dcc980f5e9cc60a2390ac949fa2b7 1 parent e60ea28
@kinsteronline authored
View
13 src/table.coffee
@@ -33,4 +33,17 @@ module.exports = class Table extends EventEmitter
@bets.push 'PASSLINEBET'
@emit 'player:bet', 'PASSLINEBET'
@emit 'player:joined', @table, player
+ player
+
+ # Is this even needed?
+ player: (arg) ->
+ return @players[arg] if typeof arg is 'number'
+ return arg if arg in @players
+
+ if typeof arg is 'string'
+ potentials = @players.filter (player) ->
+ player.uuid is arg
+ potentials[0]
+ else
+ return null
View
1  vows/player-test.coffee
@@ -36,7 +36,6 @@ vows.describe('Player').addBatch({
'then the list contains the new table': (createdTable) ->
assert.include house.listTables, createdTable
-
}).export(module)
View
14 vows/table-test.coffee
@@ -28,4 +28,18 @@ vows.describe('Craps Table').addBatch(
assert.equal table.shooter, table.players[0]
'a single bet should have been placed': (table) ->
assert.length table.bets, 1
+ 'With three players':
+ topic: ->
+ table = new Table
+ alan = table.join new Player('Alan')
+ stu = table.join new Player('Stu')
+ phil = table.join new Player('Phil')
+ [ table, alan, stu, phil ]
+ # This doesn't feel right at all...
+ 'player can be found by index': ([ table, alan, stu, phil ]) ->
+ assert.equal alan, table.player 0
+ 'player can be found by uuid': ([ table, alan, stu, phil ]) ->
+ assert.equal alan, table.player alan.uuid
+ 'player can be found by player': ([ table, alan, stu, phil ]) ->
+ assert.equal alan, table.player alan
).export(module)
Please sign in to comment.
Something went wrong with that request. Please try again.