From c20e6ef4dad20e0489972e585aa92a5980c01c35 Mon Sep 17 00:00:00 2001 From: igerashchenko Date: Sun, 22 Dec 2019 14:49:27 +0200 Subject: [PATCH 1/4] Add ATTACK method --- index.html | 5 ++++- models/monsters/crazy-dove.js | 10 ++++++++++ models/monsters/dino-nerve.js | 10 ++++++++++ models/monsters/greedy-pig.js | 11 +++++++++++ models/monsters/lazy-ira.js | 10 ++++++++++ models/unit.js | 4 ++-- 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 models/monsters/crazy-dove.js create mode 100644 models/monsters/dino-nerve.js create mode 100644 models/monsters/greedy-pig.js create mode 100644 models/monsters/lazy-ira.js diff --git a/index.html b/index.html index bcdf23b..716d4ca 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,10 @@ - + + + + ß diff --git a/models/monsters/crazy-dove.js b/models/monsters/crazy-dove.js new file mode 100644 index 0000000..c511d23 --- /dev/null +++ b/models/monsters/crazy-dove.js @@ -0,0 +1,10 @@ +var CrazyDove = (function() { + function CrazyDove(level) { + Unit.call(this, 5, 25, level); + } + + CrazyDove.prototype = Object.create(Unit.prototype); + CrazyDove.prototype.constructor = CrazyDove; + + return CrazyDove; + })(); \ No newline at end of file diff --git a/models/monsters/dino-nerve.js b/models/monsters/dino-nerve.js new file mode 100644 index 0000000..85bf052 --- /dev/null +++ b/models/monsters/dino-nerve.js @@ -0,0 +1,10 @@ +var DinoNerve = (function() { + function DinoNerve(level) { + Unit.call(this, 20, 900, level); + } + + DinoNerve.prototype = Object.create(Unit.prototype); + DinoNerve.prototype.constructor = DinoNerve; + + return DinoNerve; + })(); \ No newline at end of file diff --git a/models/monsters/greedy-pig.js b/models/monsters/greedy-pig.js new file mode 100644 index 0000000..4e3e63c --- /dev/null +++ b/models/monsters/greedy-pig.js @@ -0,0 +1,11 @@ +var GreedyPig = (function() { + function GreedyPig(level) { + Unit.call(this, 80, 10, level); + } + + GreedyPig.prototype = Object.create(Unit.prototype); + GreedyPig.prototype.constructor = GreedyPig; + + return GreedyPig; + })(); + \ No newline at end of file diff --git a/models/monsters/lazy-ira.js b/models/monsters/lazy-ira.js new file mode 100644 index 0000000..391c54e --- /dev/null +++ b/models/monsters/lazy-ira.js @@ -0,0 +1,10 @@ +var LazyIra = (function() { + function LazyIra(level) { + Unit.call(this, 10, 1000, level); + } + + LazyIra.prototype = Object.create(Unit.prototype); + LazyIra.prototype.constructor = LazyIra; + + return LazyIra; + })(); \ No newline at end of file diff --git a/models/unit.js b/models/unit.js index 45d2572..df3cc47 100644 --- a/models/unit.js +++ b/models/unit.js @@ -8,8 +8,8 @@ var Unit = (function() { this.level = level; } - Unit.prototype.attack = function() { - console.log('Attack', this); + Unit.prototype.attack = function(monster) { + return monster.damage; }; Unit.prototype.render = function() { From 8ebd4b7b9ffd2b25f8a1e3e4890858a710ab9e6a Mon Sep 17 00:00:00 2001 From: igerashchenko Date: Sun, 22 Dec 2019 15:08:42 +0200 Subject: [PATCH 2/4] Fixed deleted monster --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index 716d4ca..8dc8a19 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,7 @@ + From b23823b40b1c7027d7b5f7219bda5b3e3409f8f0 Mon Sep 17 00:00:00 2001 From: igerashchenko Date: Tue, 24 Dec 2019 00:30:40 +0200 Subject: [PATCH 3/4] Add attack method with condition --- models/unit.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/models/unit.js b/models/unit.js index df3cc47..759daa8 100644 --- a/models/unit.js +++ b/models/unit.js @@ -9,10 +9,13 @@ var Unit = (function() { } Unit.prototype.attack = function(monster) { - return monster.damage; + if (monster instanceof Unit) { + return this.health -= monster.damage; + } + console.error('You are not a monster!') }; - Unit.prototype.render = function() { + Unit.prototype.render = function() {ß return this.el; }; From 9ef0d858e5b0c716e26d1af6d0e8e951bf8eb09a Mon Sep 17 00:00:00 2001 From: igerashchenko Date: Tue, 24 Dec 2019 00:31:25 +0200 Subject: [PATCH 4/4] Fix the typo --- models/unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/unit.js b/models/unit.js index 759daa8..01ebdb6 100644 --- a/models/unit.js +++ b/models/unit.js @@ -15,7 +15,7 @@ var Unit = (function() { console.error('You are not a monster!') }; - Unit.prototype.render = function() {ß + Unit.prototype.render = function() { return this.el; };