Created
July 3, 2013 14:42
-
-
Save kinsteronline/5918594 to your computer and use it in GitHub Desktop.
So I watched Eric Leads talk at Fluent 2013...I really liked the composition he implemented...I'm going to blatantly copy it.
This file contains hidden or 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
# | |
# Base abilities mixin | |
abilitiesPrototype = (() -> | |
str = 9 | |
strAdj = 0 | |
dex = 9 | |
dexAdj = 0 | |
int = 9 | |
intAdj = 0 | |
wis = 9 | |
wisAdj = 0 | |
con = 9 | |
conAdj = 0 | |
luk = 9 | |
return { | |
constitution: -> con + conAdj | |
strength: -> str + strAdj | |
} | |
)() | |
module.exports = abilitiesPrototype | |
# | |
# Health mixin | |
_ = require 'lodash' | |
abilities = require './abilities' | |
healthPrototype = (() -> | |
wounds = 0 | |
return { | |
isDead: -> wounds >= @totalHitPoints() | |
hitPoints: -> @totalHitPoints() - wounds | |
totalHitPoints: -> @constitution() + @strength() | |
} | |
)() | |
module.exports = _.extend abilities, healthPrototype | |
# | |
# Test | |
_ = require 'lodash' | |
util = require 'util' | |
require('chai').should() | |
health = require '../src/health' | |
describe 'Health', -> | |
describe 'mixin', -> | |
before -> | |
@character = _.extend {}, health | |
it 'provides hitpoints', -> | |
@character.should.respondTo 'hitPoints' | |
it 'provides total hitpoints', -> | |
@character.should.respondTo 'totalHitPoints' | |
it 'indicates if the character is dead', -> | |
@character.should.respondTo('isDead') | |
it 'is based on basic constitution', -> | |
@character.hitPoints().should.equal(18) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment