From 8590476a689d6341dd0c7cde0f3be5f059727ef3 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:29:28 -1000 Subject: [PATCH 1/8] Added Spell constructor --- constructors.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/constructors.js b/constructors.js index d0bf11a..b5771e7 100644 --- a/constructors.js +++ b/constructors.js @@ -10,6 +10,11 @@ * @property {string} description * @method printDetails */ + function Spell (name, cost, desc){ + this.name = name; + this.cost = cost; + this.description = desc; +} /** * Returns a string of all of the spell's details. @@ -19,13 +24,13 @@ * @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). * * So you should use `Spell.call()` to assign the spell name, cost, and description. * - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call * * In addition, you will also want to assign `DamageSpell.prototype` * a value so that it inherits from `Spell`. @@ -41,8 +46,8 @@ * @property {string} name * @property {number} cost * @property {number} damage - * @property {string} description - */ + * @property {string} defscription + */ /** * Now that you've created some spells, let's create From 8a037277afc46cb7accf18db68235e0ac92b84e2 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:30:00 -1000 Subject: [PATCH 2/8] Added getDetails prototype --- constructors.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/constructors.js b/constructors.js index b5771e7..c75c7b5 100644 --- a/constructors.js +++ b/constructors.js @@ -10,7 +10,7 @@ * @property {string} description * @method printDetails */ - function Spell (name, cost, desc){ +function Spell (name, cost, desc){ this.name = name; this.cost = cost; this.description = desc; @@ -23,6 +23,9 @@ * @name getDetails * @return {string} details containing all of the spells information. */ +Spell.prototype.getDetails = function(){ + return "Name: " + this.name + 'Cost: ' + this.cost + 'Description: ' + this.description; +}; /** From 7cc2b1ae5ed7329c360c2f0b9a476526d31b43d4 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:30:31 -1000 Subject: [PATCH 3/8] Added DamageSpell constructor --- constructors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/constructors.js b/constructors.js index c75c7b5..171f15f 100644 --- a/constructors.js +++ b/constructors.js @@ -51,6 +51,10 @@ Spell.prototype.getDetails = function(){ * @property {number} damage * @property {string} defscription */ +function DamageSpell(name, cost, damage, desc){ + Spell.call(this, name, cost, desc); + this.damage = damage; +} /** * Now that you've created some spells, let's create From 477ee923fba848d9fd683c474f730be0f07d5832 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:31:00 -1000 Subject: [PATCH 4/8] Made DamageSpell same type as spell --- constructors.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/constructors.js b/constructors.js index 171f15f..df03abe 100644 --- a/constructors.js +++ b/constructors.js @@ -56,6 +56,8 @@ function DamageSpell(name, cost, damage, desc){ this.damage = damage; } +DamageSpell.prototype = Object.create(Spell.prototype); + /** * Now that you've created some spells, let's create * `Spellcaster` objects that can use them! From dd9f9cbdec9cc83c0756f19834b056430774cabd Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:31:25 -1000 Subject: [PATCH 5/8] Added Spellcaster constructor --- constructors.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/constructors.js b/constructors.js index df03abe..ced5771 100644 --- a/constructors.js +++ b/constructors.js @@ -74,7 +74,12 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @method spendMana * @method invoke */ - +function Spellcaster(name, health, mana){ + this.name = name; + this.health = health; + this.mana = mana; + this.isAlive = true; +} /** * @method inflictDamage * From 9b817f50b15367f63a3434730182e36ac20eab8b Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:32:15 -1000 Subject: [PATCH 6/8] Added inflictDamage prototype --- constructors.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/constructors.js b/constructors.js index ced5771..bc9cfe2 100644 --- a/constructors.js +++ b/constructors.js @@ -91,6 +91,13 @@ function Spellcaster(name, health, mana){ * @param {number} damage Amount of damage to deal to the spellcaster */ +Spellcaster.prototype.inflictDamage = function(number){ + this.health -= number; + if(this.health <= 0){ + this.health = 0; + this.isAlive = false; + } +}; /** * @method spendMana * From 61660230e7591e563f695cb3d85e38690ebea3f8 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:32:44 -1000 Subject: [PATCH 7/8] Added spendMana prototype --- constructors.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/constructors.js b/constructors.js index bc9cfe2..8f66db4 100644 --- a/constructors.js +++ b/constructors.js @@ -108,6 +108,14 @@ Spellcaster.prototype.inflictDamage = function(number){ * @return {boolean} success Whether mana was successfully spent. */ +Spellcaster.prototype.spendMana = function(cost){ + if(this.mana - cost < 0) + return false; + else{ + this.mana -= cost; + return true; + } +}; /** * @method invoke * From f53e3cfb6276cd4aa7dded018d27bf3310758783 Mon Sep 17 00:00:00 2001 From: Tanachi Date: Thu, 26 May 2016 18:33:13 -1000 Subject: [PATCH 8/8] Added invoke prototype --- constructors.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/constructors.js b/constructors.js index 8f66db4..0bf96aa 100644 --- a/constructors.js +++ b/constructors.js @@ -142,3 +142,21 @@ Spellcaster.prototype.spendMana = function(cost){ * @param {Spellcaster} target The spell target to be inflicted. * @return {boolean} Whether the spell was successfully cast. */ +Spellcaster.prototype.invoke = function(Magic,Person){ + if((Magic instanceof DamageSpell) === false && (Magic instanceof Spell) === false) + return false; + else{ + if(Magic instanceof Spell && !Person && (Magic instanceof DamageSpell) === false) + return this.spendMana(Magic.cost); + else if(Magic instanceof DamageSpell && !Person) + return false; + else{ + if(this.spendMana(Magic.cost)){ + Person.inflictDamage(Magic.damage); + return true; + } + return false; + } + + } +}; \ No newline at end of file