{ // 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(){ var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) this.Class = function(){ }; // Create a new Class that inherits from this class Class.extend = function(prop, ref_name) { if(ref_name) reflection[ref_name] = Class; var _super = this.prototype; // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { return function() { var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } // The dummy class constructor function Class() { // All construction is actually done in the init method if ( !initializing && this.init ) this.init.apply(this, arguments); } // Populate our constructed prototype object Class.prototype = prototype; // Enforce the constructor to be what we expect Class.prototype.constructor = Class; // And make this class extendable Class.extend = arguments.callee; 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){ /* info: pname, cname,class, level, experience, race, size * attributes: body, agility, spirit * properties: strength, hardness, movement, skill, mind, aura * drawinfo: x,y,w,h,col */ this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"", "size":info["size"]*1}; this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1, "spirit": attributes["spirit"]*1}; 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}; this.graphelement = Crafty.e("Creature").creature(this.info["pname"],drawinfo["x"],drawinfo["y"], drawinfo["w"],drawinfo["h"],drawinfo["col"]); this.battle = {}; if(battle) { this.battle={"life": battle["life"]*1, "defense": battle["defense"]*1,"ini":battle["ini"]*1, "walk": battle["walk"]*1, "melee": battle["melee"]*1, "shoot": battle["shoot"]*1, "chant": battle["chant"]*1, "shoot_chant": battle["shoot_chant"]*1}; } else { this.battle["life"] = this.attributes.body + this.properties.strength + 10;; this.battle["defense"] = this.attributes.body + this.properties.hardness; this.battle["ini"] = this.attributes.agility + this.properties.movement; this.battle["walk"] = (this.attributes.agility / 2) +1; this.battle["melee"] = this.attributes.body + this.properties.strength; this.battle["shoot"] = this.attributes.agility + this.properties.mind; this.battle["chant"] = this.attributes.spirit + this.properties.aura; this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill; }; this.life = this.battle["life"]*1; this.att = "melee"; }, attack: function(enem) { 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?
"; outstr += ""; $('#ui').html(outstr); $('#att').bind("change", function() {cur_sel.att=this.value;}); $("#"+this.att).get(0).selected="true"; } }); var Player = Creature.extend({ init: function(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) { /* info: pname, cname,class, level, experience, race, size * attributes: body, agility, spirit * properties: strength, hardness, movement, skill, mind, aura * drawinfo: x,y,w,h,col */ this._super(info,attributes,properties,drawinfo,battle); this.info["cname"]= info["cname"]+""; this.info["class"]= info["class"]+""; this.info["level"]= info["level"]*1; // Set default battle-propoerties. this.extern = {"armor":0,"chant":0,"weapon":0}; this.battle.defense += this.extern.armor; this.battle.melee += this.extern.weapon; this.battle.shoot += this.extern.weapon; this.battle.chant = this.battle.chant + this.extern.chant - this.extern.armor; this.battle.shoot_chant = this.battle.chant + this.extern.chant - this.extern.armor; }, printoutput: function() { 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); } }); var Beast = Creature.extend({ init: function(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) { /* info: pname, experience, race, size * attributes: body, agility, spirit * properties: strength, hardness, movement, skill, mind, aura * drawinfo: x,y,w,h,col * battle: life, defense,ini,walk,melee,shoot,chant,shoot_chant */ this._super(info,attributes,properties,drawinfo,battle); this.info.cname=this.info.pname; this.enem = true; }, printoutput: function() { 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); } }); }