From e0905512146c8d1b9e547395ff032b6fd1dd69ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 25 Sep 2014 11:49:30 +0200 Subject: [PATCH 1/3] Self-Attacks now forbidden --- index.html | 2 ++ src/jsds_crafty.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 4fd0ddc..32ee965 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,8 @@
+
+
diff --git a/src/jsds_crafty.js b/src/jsds_crafty.js index fad6d0c..5bed572 100644 --- a/src/jsds_crafty.js +++ b/src/jsds_crafty.js @@ -78,7 +78,13 @@ this.enableControl(); }; if(e.mouseButton === Crafty.mouseButtons.RIGHT) { - cur_sel.attack(player[this.id]); + if ( !cur_sel ) { return; }; + if ( cur_sel == player[this.id]) + { + } + else { + cur_sel.attack(player[this.id]); + }; }; }); From 3a37375cf203f17a57d07f464c0e46e8a2d9afe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 25 Sep 2014 13:06:35 +0200 Subject: [PATCH 2/3] Attack is selectable --- index.html | 2 +- src/jsds.js | 29 ++++++++++++++++++++++++----- src/jsds_crafty.js | 3 ++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 32ee965..f0ed19a 100644 --- a/index.html +++ b/index.html @@ -8,9 +8,9 @@

JSDSH - Javascript Dungeonslayers Helper

+
-
diff --git a/src/jsds.js b/src/jsds.js index 195cc25..850af19 100644 --- a/src/jsds.js +++ b/src/jsds.js @@ -1,5 +1,8 @@ { - // OOP-Setup + // OOP-Setup, thanks to Florian Rappl for this piece of Code + // Source: + // http://www.florian-rappl.de/Articles/Page/116/super-mario5-article + var reflection = {}; (function(){ @@ -72,13 +75,10 @@ * properties: strength, hardness, movement, skill, mind, aura * drawinfo: x,y,w,h,col */ - console.log("Creature called!"); this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"", "size":info["size"]*1}; - console.log("Creature Ready!"); this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1, "spirit": attributes["spirit"]*1}; - console.log("Problem?"); this.properties = {"strength": properties["strength"]*1 , "hardness": properties["hardness"]*1, "movement": properties["movement"]*1, "skill": properties["skill"]*1, "mind": properties["mind"]*1, "aura": properties["aura"]*1}; @@ -102,12 +102,29 @@ this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill; }; this.life = this.battle["life"]*1; + this.att = "melee"; + console.log("Attack: "+this.att); }, attack: function(enem) { //console.log("attack"); console.log(this.info.cname+" greift "+enem.info.cname+" an!"); - console.log("Ergebnis: " + this.battle.melee + ( this.battle.melee > enem.battle.defense ? " > " : " < ") + enem.battle.defense); + console.log("Ergebnis: " + this.battle[this.att] + + ( this.battle[this.att] > enem.battle.defense ? " > " : " < ") + enem.battle.defense); + }, + sel_att: function() { + var outstr=""; + outstr += "Angriffstyp?
"; + outstr += ""; + $('#ui').html(outstr); + $('#att').bind("change", function() {cur_sel.att=this.value;}); + $("#"+this.att).get(0).selected="true"; } + }); var Player = Creature.extend({ @@ -133,6 +150,7 @@ }, printoutput: function() { $('#output').empty(); + $('#ui').empty(); $('#output').html(this.info.cname+"
"+this.info.pname); } }); @@ -151,6 +169,7 @@ }, printoutput: function() { $('#output').empty(); + $('#ui').empty(); $('#output').html(this.info.race+"
"+this.info.pname); } }); diff --git a/src/jsds_crafty.js b/src/jsds_crafty.js index 5bed572..e1a48a2 100644 --- a/src/jsds_crafty.js +++ b/src/jsds_crafty.js @@ -79,8 +79,9 @@ }; if(e.mouseButton === Crafty.mouseButtons.RIGHT) { if ( !cur_sel ) { return; }; - if ( cur_sel == player[this.id]) + if ( cur_sel == player[this.id] ) { + cur_sel.sel_att(); } else { cur_sel.attack(player[this.id]); From c419d6c2cff6272dbce642668bcba6298ee700a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 25 Sep 2014 15:23:54 +0200 Subject: [PATCH 3/3] Attack now only misses range-stuff --- src/base_ui.js | 2 +- src/jsds.js | 105 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 94 insertions(+), 13 deletions(-) diff --git a/src/base_ui.js b/src/base_ui.js index d98d154..90c9eb5 100644 --- a/src/base_ui.js +++ b/src/base_ui.js @@ -1,3 +1,3 @@ $(document).ready( function() { - $('#load').click(function() { $.getScript("src/adventure_01.js");}); + $('#load').click(function() { $.getScript("src/adventure_01.js"); $('#load').hide();}); }); diff --git a/src/jsds.js b/src/jsds.js index 850af19..c1dc90d 100644 --- a/src/jsds.js +++ b/src/jsds.js @@ -67,6 +67,28 @@ return Class; }; })(); + + // Helper-Funcs + + var clearui = function() { + $('#output').empty(); + $('#ui').empty(); + }; + + var dice = function(probe) { + var diceval = Math.floor(Math.random() * (21 - 1)) + 1; + if ( diceval <= probe ) { + return diceval; + } + else { + if (diceval === 20) { + alert ("Patzer!"); + }; + return 0; + }; + }; + + // Own Classes for Creatures, etc var Creature = Class.extend({ init: function(info,attributes,properties,drawinfo,battle){ @@ -103,14 +125,64 @@ }; this.life = this.battle["life"]*1; this.att = "melee"; - console.log("Attack: "+this.att); }, + attack: function(enem) { - //console.log("attack"); - console.log(this.info.cname+" greift "+enem.info.cname+" an!"); - console.log("Ergebnis: " + this.battle[this.att] - + ( this.battle[this.att] > enem.battle.defense ? " > " : " < ") + enem.battle.defense); + clearui(); + var output=$('#output'); + output.html(this.info.cname+" greift "+enem.info.cname+" an!
"); + var attack_val = dice(this.battle[this.att]); + if (! attack_val ) { + output.append('Angriff Fehlgeschlagen!
'); + } + else { + output.append(this.info.cname + " trifft mit " + attack_val + "
"); + var defense_val = dice(this.battle.defense); + console.log(attack_val + ", " + defense_val); + attack_val -= defense_val; + attack_val = Math.max(attack_val, 0); + if ( ! defense_val ) { + output.append(enem.info.cname + " kann sich nicht wehren!
"); + } + else { + output.append(enem.info.cname + " wehrt sich mit " + defense_val+".
"); + } + if ( attack_val === 0 ) { + output.append("Vollständig Abgewehrt!
"); + } + else { + output.append("Schaden: "+attack_val+"
"); + }; + enem.life -= attack_val; + if( enem.life <= 0 ) { + if ( enem.enem ){ + output.append(enem.info.cname + " ist besiegt
"); + enem.die(); + } + else { + output.append(enem.info.cname + " ist bewusstlos
"); + enem.unconsc(); + }; + } + } }, + + die: function() { + this.graphelement.destroy(); + delete(player[this.info.pname]); + }, + + unconsc: function() { + this.graphelement.oldcolor = this.graphelement.color(); + this.graphelement.color("#A0A0C0"); + }, + + consc: function() { + if ( this.graphelement.oldcolor ) { + this.graphelement.color(this.graphelement.oldcolor); + } + }, + sel_att: function() { var outstr=""; outstr += "Angriffstyp?
"; @@ -141,7 +213,6 @@ // Set default battle-propoerties. this.extern = {"armor":0,"chant":0,"weapon":0}; - console.log(this.battle.defense); this.battle.defense += this.extern.armor; this.battle.melee += this.extern.weapon; this.battle.shoot += this.extern.weapon; @@ -149,9 +220,13 @@ this.battle.shoot_chant = this.battle.chant + this.extern.chant - this.extern.armor; }, printoutput: function() { - $('#output').empty(); - $('#ui').empty(); - $('#output').html(this.info.cname+"
"+this.info.pname); + outstr = ""; + outstr += this.info.cname + " (gespielt von "+this.info.pname +")
"; + outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von " + + this.battle[this.att] + " an.
"; + outstr += "Verteidigungsstärke: " + this.battle.defense + "
"; + outstr += "Kraftpunkte: " + this.life; + $('#output').html(outstr); } }); @@ -166,11 +241,17 @@ this._super(info,attributes,properties,drawinfo,battle); this.info.cname=this.info.pname; + this.enem = true; }, printoutput: function() { - $('#output').empty(); - $('#ui').empty(); - $('#output').html(this.info.race+"
"+this.info.pname); + clearui(); + outstr = ""; + outstr += "Ein "+ this.info.race + "
"; + outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von " + + this.battle[this.att] + " an.
"; + outstr += "Verteidigungsstärke: " + this.battle.defense + "
"; + outstr += "Kraftpunkte: " + this.life; + $('#output').html(outstr); } }); }