From 5f035ec719274252dc55aaf48847c3541a5e4a1d Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:20:50 -1000 Subject: [PATCH 01/12] Created a Spell Function --- constructors.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/constructors.js b/constructors.js index d0bf11a..db4ed73 100644 --- a/constructors.js +++ b/constructors.js @@ -11,6 +11,16 @@ * @method printDetails */ +function Spell( name, cost, description ){ + this.name = function() { + return 'name'; + }; +} + +Spell.prototype.name = function(){ + return 'name'; +}; + /** * 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. @@ -44,6 +54,10 @@ * @property {string} description */ +function DamageSpell(name,cost,damage,description){ + +} + /** * Now that you've created some spells, let's create * `Spellcaster` objects that can use them! @@ -61,6 +75,10 @@ * @method invoke */ + function Spellcaster(name,health,mana){ + + } + /** * @method inflictDamage * From 89b4d072278a76e8aa51d72068b672eb8e5f7594 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:22:09 -1000 Subject: [PATCH 02/12] Spell has a name --- constructors.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/constructors.js b/constructors.js index db4ed73..f4d3b24 100644 --- a/constructors.js +++ b/constructors.js @@ -12,15 +12,9 @@ */ function Spell( name, cost, description ){ - this.name = function() { - return 'name'; - }; + this.name = name; } -Spell.prototype.name = function(){ - return 'name'; -}; - /** * 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. From a18e7c236922a7971395fe2aee0915cb847630dc Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:23:01 -1000 Subject: [PATCH 03/12] Spell has a cost --- constructors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/constructors.js b/constructors.js index f4d3b24..cb1c9a7 100644 --- a/constructors.js +++ b/constructors.js @@ -13,6 +13,7 @@ function Spell( name, cost, description ){ this.name = name; + this.cost = cost; } /** From 5b4eb9fbe4df788619f7b063278f21ad48329b42 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:23:25 -1000 Subject: [PATCH 04/12] Spell has a description --- constructors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/constructors.js b/constructors.js index cb1c9a7..af2fb48 100644 --- a/constructors.js +++ b/constructors.js @@ -14,6 +14,7 @@ function Spell( name, cost, description ){ this.name = name; this.cost = cost; + this.description = description; } /** From 92aa3a289185363896c5ab892e6f266e583666e0 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:44:39 -1000 Subject: [PATCH 05/12] Spell's information is a string --- constructors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/constructors.js b/constructors.js index af2fb48..27c482a 100644 --- a/constructors.js +++ b/constructors.js @@ -17,6 +17,10 @@ function Spell( name, cost, description ){ this.description = description; } +Spell.prototype.getDetails = function(){ + return this.name + ' ' + this.cost + ' ' + this.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. From 4832b0380b3e04464a580cb21f473dcfd66d42cf Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:51:23 -1000 Subject: [PATCH 06/12] Call Spells constructor function --- constructors.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/constructors.js b/constructors.js index 27c482a..9f2da66 100644 --- a/constructors.js +++ b/constructors.js @@ -55,7 +55,8 @@ Spell.prototype.getDetails = function(){ */ function DamageSpell(name,cost,damage,description){ - + Spell.call( this, name, cost, description ); + this.damage = 'damage'; } /** From e80bda2e5b05198b25858bf43808a9af57c668fb Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 18:53:14 -1000 Subject: [PATCH 07/12] instance object --- constructors.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/constructors.js b/constructors.js index 9f2da66..434c151 100644 --- a/constructors.js +++ b/constructors.js @@ -56,9 +56,13 @@ Spell.prototype.getDetails = function(){ function DamageSpell(name,cost,damage,description){ Spell.call( this, name, cost, description ); - this.damage = 'damage'; + this.damage = damage; } +DamageSpell.prototype.Spell = function(){ + +}; + /** * Now that you've created some spells, let's create * `Spellcaster` objects that can use them! From f42dad7bb9047dea2c8e234defa5fd1a512d1ff7 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 19:06:10 -1000 Subject: [PATCH 08/12] Spellcaster instance Object --- constructors.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/constructors.js b/constructors.js index 434c151..a0e1696 100644 --- a/constructors.js +++ b/constructors.js @@ -59,9 +59,7 @@ function DamageSpell(name,cost,damage,description){ this.damage = damage; } -DamageSpell.prototype.Spell = function(){ - -}; +DamageSpell.prototype = Object.create(Spell.prototype); /** * Now that you've created some spells, let's create @@ -81,7 +79,9 @@ DamageSpell.prototype.Spell = function(){ */ function Spellcaster(name,health,mana){ - + this.name = name; + this.health = health; + this.mana = mana; } /** From ba799da6c3b721aadcaeafe4782e2281db0fbc2b Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 19:09:28 -1000 Subject: [PATCH 09/12] should be alive --- constructors.js | 1 + 1 file changed, 1 insertion(+) diff --git a/constructors.js b/constructors.js index a0e1696..9f32994 100644 --- a/constructors.js +++ b/constructors.js @@ -82,6 +82,7 @@ DamageSpell.prototype = Object.create(Spell.prototype); this.name = name; this.health = health; this.mana = mana; + this.isAlive = true; } /** From 3023b0ae96b681e26a78ca7ca332aa524e8937fb Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 19:11:03 -1000 Subject: [PATCH 10/12] inflictDamage --- constructors.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/constructors.js b/constructors.js index 9f32994..140241b 100644 --- a/constructors.js +++ b/constructors.js @@ -96,6 +96,10 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @param {number} damage Amount of damage to deal to the spellcaster */ + Spellcaster.prototype.inflictDamage = function(){ + + }; + /** * @method spendMana * From 37d3b872446989d135c5804325ba260af8f51f64 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Thu, 26 May 2016 19:40:17 -1000 Subject: [PATCH 11/12] inflictDamage --- constructors.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/constructors.js b/constructors.js index 140241b..22d6188 100644 --- a/constructors.js +++ b/constructors.js @@ -96,8 +96,12 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @param {number} damage Amount of damage to deal to the spellcaster */ - Spellcaster.prototype.inflictDamage = function(){ - + Spellcaster.prototype.inflictDamage = function(damage){ + damage = this.health--; + if(this.health !== damage || this.health < 0){ + this.isAlive = false; + this.health = 0; + } }; /** @@ -110,6 +114,10 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @return {boolean} success Whether mana was successfully spent. */ + Spellcaster.prototype.spendMana = function(){ + + }; + /** * @method invoke * From bb71b0bf565ffe03d15b6f5d3c2a3ae4c435f530 Mon Sep 17 00:00:00 2001 From: Nikki K <808nikz@gmail.com> Date: Tue, 31 May 2016 20:29:26 -1000 Subject: [PATCH 12/12] Invoke --- constructors.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/constructors.js b/constructors.js index 22d6188..df451a0 100644 --- a/constructors.js +++ b/constructors.js @@ -97,8 +97,8 @@ DamageSpell.prototype = Object.create(Spell.prototype); */ Spellcaster.prototype.inflictDamage = function(damage){ - damage = this.health--; - if(this.health !== damage || this.health < 0){ + this.health -= damage; + if(this.health <= 0){ this.isAlive = false; this.health = 0; } @@ -114,8 +114,13 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @return {boolean} success Whether mana was successfully spent. */ - Spellcaster.prototype.spendMana = function(){ - + Spellcaster.prototype.spendMana = function(cost){ + if(this.mana >= cost) { + this.mana = this.mana - cost; + return true; + } else { + return false; + } }; /** @@ -144,3 +149,23 @@ DamageSpell.prototype = Object.create(Spell.prototype); * @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 === undefined || spell === null) { + return false; + } + if (spell instanceof DamageSpell && target instanceof Spellcaster) { + if(this.spendMana(spell.cost)) { + target.inflictDamage(spell.damage); + return true; + } + } + if (spell instanceof DamageSpell && !(target instanceof Spellcaster)) { + return false; + } else { + if(this.spendMana(spell.cost)){ + return true; + } + } + return false; + };