From 0515d0456a490a0b5925e71ca27f89c8de8342ca Mon Sep 17 00:00:00 2001 From: Lisa Date: Mon, 23 May 2016 00:14:13 -1000 Subject: [PATCH 1/6] Pass Spell tests --- constructors.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/constructors.js b/constructors.js index d0bf11a..a0167d4 100644 --- a/constructors.js +++ b/constructors.js @@ -10,7 +10,11 @@ * @property {string} description * @method printDetails */ - + function Spell(name, cost, description) { + this.name = name; + this.cost = cost; + this.description = description; + } /** * Returns a string of all of the spell's details. * The format doesn't matter, as long as it contains the spell name, cost, and description. @@ -18,6 +22,9 @@ * @name getDetails * @return {string} details containing all of the spells information. */ + Spell.prototype.getDetails = function () { + return "You cast " + this.name + " which cost " + this.cost + " and does " + this.description; + }; /** * A spell that deals damage. From e4570abcd84d9337d062a2bc3ce94a1c9236d581 Mon Sep 17 00:00:00 2001 From: Lisa Date: Mon, 23 May 2016 00:23:07 -1000 Subject: [PATCH 2/6] Pass DamageSpell tests --- constructors.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/constructors.js b/constructors.js index a0167d4..3f3e8b2 100644 --- a/constructors.js +++ b/constructors.js @@ -50,6 +50,11 @@ * @property {number} damage * @property {string} description */ + function DamageSpell(name, cost, damage, description) { + Spell.call(this, name, cost, description); + this.damage = damage; + } + DamageSpell.prototype = Object.create(Spell.prototype); /** * Now that you've created some spells, let's create From 467606a05e3f757ba3061c967d0eb9e6a23e0383 Mon Sep 17 00:00:00 2001 From: Lisa Date: Mon, 23 May 2016 00:31:55 -1000 Subject: [PATCH 3/6] Create Spellcaster function and pass 'instance object' tests --- constructors.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/constructors.js b/constructors.js index 3f3e8b2..7639b8d 100644 --- a/constructors.js +++ b/constructors.js @@ -72,6 +72,12 @@ * @method spendMana * @method invoke */ + function Spellcaster(name, health, mana) { + this.name = name; + this.health = health; + this.mana = mana; + this.isAlive = true; + } /** * @method inflictDamage From 37f3451a0c0860f7db3c2359dc78087cd4c3c511 Mon Sep 17 00:00:00 2001 From: Lisa Date: Mon, 23 May 2016 00:33:16 -1000 Subject: [PATCH 4/6] Pass '.inflictDamage' tests for Spellcaster function --- constructors.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/constructors.js b/constructors.js index 7639b8d..0487a61 100644 --- a/constructors.js +++ b/constructors.js @@ -89,6 +89,13 @@ * * @param {number} damage Amount of damage to deal to the spellcaster */ + Spellcaster.prototype.inflictDamage = function (damage) { + this.health -=damage; + if (this.health < damage){ + this.health = 0; + this.isAlive = false; + } + }; /** * @method spendMana From 762df8f9cac11b7401172d139ca8ab71df280322 Mon Sep 17 00:00:00 2001 From: Lisa Date: Mon, 23 May 2016 00:43:40 -1000 Subject: [PATCH 5/6] Pass '.spendMana' tests for Spellcaster function --- constructors.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/constructors.js b/constructors.js index 0487a61..fd94e28 100644 --- a/constructors.js +++ b/constructors.js @@ -106,6 +106,14 @@ * @param {number} cost The amount of mana to spend. * @return {boolean} success Whether mana was successfully spent. */ + Spellcaster.prototype.spendMana = function (cost) { + if (this.mana > cost){ + this.mana -=cost; + return true; + }else{ + return false; + } + }; /** * @method invoke From dfc5b552259a2ad4eebd65c989f77db31850343f Mon Sep 17 00:00:00 2001 From: Lisa Date: Tue, 24 May 2016 23:01:37 -1000 Subject: [PATCH 6/6] update .inflictDamage and .spendMana method as well as pass tests for .invoke method --- constructors.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/constructors.js b/constructors.js index fd94e28..12a0ead 100644 --- a/constructors.js +++ b/constructors.js @@ -91,7 +91,7 @@ */ Spellcaster.prototype.inflictDamage = function (damage) { this.health -=damage; - if (this.health < damage){ + if (this.health <= damage){ this.health = 0; this.isAlive = false; } @@ -107,7 +107,7 @@ * @return {boolean} success Whether mana was successfully spent. */ Spellcaster.prototype.spendMana = function (cost) { - if (this.mana > cost){ + if (this.mana >= cost){ this.mana -=cost; return true; }else{ @@ -141,3 +141,22 @@ * @param {Spellcaster} target The spell target to be inflicted. * @return {boolean} Whether the spell was successfully cast. */ + Spellcaster.prototype.invoke = function (spell, target) { + if (!(spell instanceof Spell)){ + return false; + } + + if(spell instanceof DamageSpell && (!(target instanceof Spellcaster))){ + return false; + } + + if (this.mana >= spell.cost){ + this.spendMana(spell.cost); + if (spell instanceof DamageSpell){ + target.inflictDamage(spell.damage); + } + return true; + }else{ + return false; + } + };