From 5fb23e9a88fd08d1870b933901abcc5503df0fd1 Mon Sep 17 00:00:00 2001 From: marunoa Date: Wed, 25 May 2016 16:07:17 -1000 Subject: [PATCH 1/2] in progress --- constructors.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/constructors.js b/constructors.js index d0bf11a..669718f 100644 --- a/constructors.js +++ b/constructors.js @@ -11,6 +11,14 @@ * @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. @@ -19,6 +27,8 @@ * @return {string} details containing all of the spells information. */ + + /** * A spell that deals damage. * We want to keep this code DRY (Don't Repeat Yourself). From a863978b6d8e6d1710147ab9c2334139a65f8a61 Mon Sep 17 00:00:00 2001 From: marunoa Date: Thu, 26 May 2016 19:49:20 -1000 Subject: [PATCH 2/2] passed 25 tests --- constructors.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/constructors.js b/constructors.js index 669718f..8e6d1f9 100644 --- a/constructors.js +++ b/constructors.js @@ -27,7 +27,13 @@ function Spell (name, cost, description) { * @return {string} details containing all of the spells information. */ + Spell.prototype.getDetails = function () { + var string = this.name + ", " + this.cost + ", " + this.description + ". "; + + return string.toString(); + + }; /** * A spell that deals damage. @@ -54,6 +60,19 @@ function Spell (name, cost, description) { * @property {string} description */ + function DamageSpell (name, cost, damage, description) { + + this.name = name; + this.cost = cost; + this.damage = damage; + this.description = description; + + Spell.call(this, name, cost, description); + + } + + + /** * Now that you've created some spells, let's create * `Spellcaster` objects that can use them! @@ -71,6 +90,15 @@ function Spell (name, cost, description) { * @method invoke */ + function Spellcaster (name, health, mana) { + + this.name = name; + this.health = health; + this.mana = mana; + this.isAlive = true; + + } + /** * @method inflictDamage * @@ -82,6 +110,20 @@ function Spell (name, cost, description) { * @param {number} damage Amount of damage to deal to the spellcaster */ + Spellcaster.prototype.inflictDamage = function (damage) { + + this.health -= damage; + + if (this.health = 0 || this.health < 0) { + + this.health = 0; + + } + + this.isAlive = false; + + }; + /** * @method spendMana * @@ -92,6 +134,22 @@ function Spell (name, cost, description) { * @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 * @@ -118,3 +176,19 @@ function Spell (name, cost, description) { * @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; + + } else { + + return true; + + } + + + + }; \ No newline at end of file