Add hpDisplay function

This commit is contained in:
Blade Barringer
2015-07-18 13:12:11 -05:00
parent f9304bd28f
commit 17ef7e2885
2 changed files with 26 additions and 0 deletions

View File

@@ -15,6 +15,23 @@ describe('Stats Service', function() {
}); });
}); });
describe('hpDisplay', function() {
it('displays hp as "hp / totalHP"', function() {
var hp = 34;
var hpDisplay = statCalc.hpDisplay(hp);
expect(hpDisplay).to.eql('34/50');
});
it('Rounds hp up when given a decimal', function() {
var hp = 34.4;
var hpDisplay = statCalc.hpDisplay(hp);
expect(hpDisplay).to.eql('35/50');
});
});
describe('levelBonus', function() { describe('levelBonus', function() {
it('calculates bonus as half of level for even numbered level under 100', function() { it('calculates bonus as half of level for even numbered level under 100', function() {
var level = 50; var level = 50;

View File

@@ -12,6 +12,14 @@
function statsFactory(Content, Shared) { function statsFactory(Content, Shared) {
function hpDisplay(hp) {
var remainingHP = Math.ceil(hp);
var totalHP = Shared.maxHealth;
var display = remainingHP + '/' + totalHP;
return display;
}
function levelBonus(level) { function levelBonus(level) {
// Level bonus is derived by taking the level, subtracting one, // Level bonus is derived by taking the level, subtracting one,
// taking the smaller of it or maxLevel (100), // taking the smaller of it or maxLevel (100),
@@ -59,6 +67,7 @@
return { return {
classBonus: classBonus, classBonus: classBonus,
equipmentStatBonus: equipmentStatBonus, equipmentStatBonus: equipmentStatBonus,
hpDisplay: hpDisplay,
levelBonus: levelBonus levelBonus: levelBonus
} }
} }