Skip to content

Commit

Permalink
feat(game): play() returns an array of cards
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 23, 2017
1 parent 7504123 commit 5421c81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ Game.prototype.play = function play(card) {
var self = this, trick, seat;

// Argument overloading
if (arguments.length === 0) {
var a = [];
this.tricks.forEach(function (trick) {
trick.play.forEach(function(p) { a.push(p.card); });
});
return a;
}
if (arguments.length > 1) {
card = Array.prototype.slice.call(arguments);
}
Expand Down
10 changes: 10 additions & 0 deletions test/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ describe('Game', function() {
expect(game.tricks[0].play[1].card).to.equal(bridge.card.S2);
});

it('should return an array of cards', function() {
var game = new Game();
game.contract.level = 3;
game.contract.denomination = 'NT';
game.contract.declaror = bridge.seat.south;
game.play('AS', bridge.card.S2);
var play = game.play();
expect(play).to.have.length(2).and.eql([bridge.card.SA, bridge.card.S2]);
});

});

});

0 comments on commit 5421c81

Please sign in to comment.