Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Player creation now working with DeckList
- Loading branch information
Lauren Voswinkel
committed
Feb 28, 2015
1 parent
f228d0a
commit 9a1e8f1
Showing
13 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
function Player(options){ | ||
var DeckList = require('./deck_list'); | ||
|
||
function Player(options, finalize){ | ||
var player = this; | ||
options = options || {}; | ||
this.deck = options.deck; | ||
if(this.deck == undefined) throw Error('Player has no Deck'); | ||
finalize = finalize || function(){}; | ||
|
||
new DeckList(options.deck, function(err){ | ||
if(err != undefined){ return finalize(err) } | ||
|
||
this.identity = options.deck.identity; | ||
if(this.identity == undefined) throw Error('Player has no Identity'); | ||
player.identity = this.identity; | ||
player.deck = this.cards; | ||
player.scored_agendas = []; | ||
player.credits = 5; | ||
player.hand = []; | ||
|
||
this.scored_agendas = []; | ||
this.credits = 0; | ||
this.hand = []; | ||
player.identity.prepare(player); | ||
finalize(); | ||
}) | ||
} | ||
|
||
module.exports = Player; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require('../../support'); | ||
var netrunner = require('../../../') | ||
, Player = netrunner.Player | ||
, fixtures = require('../../fixtures/') | ||
, Base = new fixtures.Base() | ||
, expect = require('expect.js'); | ||
|
||
describe('GameFactory', function(){ | ||
describe('::create', function(){ | ||
xit('requires two players', function(done){ | ||
p1 = new Player({deck: Base.corp_legit_deck_list()}); | ||
new GameFactory(p1, function(err){ | ||
expect(err).to.be.an(Error); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
var netrunner = require('../../') | ||
, Player = netrunner.Player | ||
, fixtures = require('../fixtures/') | ||
, Base = new fixtures.Base() | ||
, expect = require('expect.js'); | ||
|
||
|
||
describe('Player', function(){ | ||
describe('#new', function(){ | ||
var test_function = function(opts){ | ||
new Player(opts); | ||
var test_function = function(opts, finalize){ | ||
new Player(opts, finalize); | ||
} | ||
it('throws an error if no deck is present', function(){ | ||
expect(test_function).to.throwException(/player has no deck/i); | ||
}) | ||
|
||
it('throws an error if no identity is present', function(){ | ||
expect(test_function).withArgs({deck: {}}).to.throwException(/player has no identity/i); | ||
it('throws an error if DeckList encounters an error', function(done){ | ||
test_function(undefined, function(err){ | ||
expect(err.message).to.match(/deck list has no identity/i); | ||
done(); | ||
}); | ||
}) | ||
|
||
it('returns a Player if identity is given', function(){ | ||
player = new Player({deck: {identity: 'Derp'}}); | ||
expect(player).to.be.a(Player); | ||
it('returns a Player if DeckList builds successfully', function(done){ | ||
var player = new Player({deck: Base.corp_legit_deck_list()}, function(){ | ||
expect(player).to.be.a(Player); | ||
done(); | ||
}); | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters