Merge branch 'attack'
This commit is contained in:
commit
e2d4a73d81
4 changed files with 123 additions and 14 deletions
|
@ -8,8 +8,10 @@
|
||||||
<h1>JSDSH - Javascript Dungeonslayers Helper</h1>
|
<h1>JSDSH - Javascript Dungeonslayers Helper</h1>
|
||||||
|
|
||||||
<div id="game"></div>
|
<div id="game"></div>
|
||||||
|
<div id="ui"></div>
|
||||||
<button id="load">Load</button>
|
<button id="load">Load</button>
|
||||||
<div id="output"></div>
|
<div id="output"></div>
|
||||||
|
</div>
|
||||||
<script type="text/javascript" src="lib/crafty.js"></script>
|
<script type="text/javascript" src="lib/crafty.js"></script>
|
||||||
<script type="text/javascript" src="lib/jquery-1.11.1.min.js"></script>
|
<script type="text/javascript" src="lib/jquery-1.11.1.min.js"></script>
|
||||||
<script type="text/javascript" src="src/jsds_crafty.js"></script>
|
<script type="text/javascript" src="src/jsds_crafty.js"></script>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
$(document).ready( function() {
|
$(document).ready( function() {
|
||||||
$('#load').click(function() { $.getScript("src/adventure_01.js");});
|
$('#load').click(function() { $.getScript("src/adventure_01.js"); $('#load').hide();});
|
||||||
});
|
});
|
||||||
|
|
124
src/jsds.js
124
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 = {};
|
var reflection = {};
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
@ -65,6 +68,28 @@
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// 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({
|
var Creature = Class.extend({
|
||||||
init: function(info,attributes,properties,drawinfo,battle){
|
init: function(info,attributes,properties,drawinfo,battle){
|
||||||
/* info: pname, cname,class, level, experience, race, size
|
/* info: pname, cname,class, level, experience, race, size
|
||||||
|
@ -72,13 +97,10 @@
|
||||||
* properties: strength, hardness, movement, skill, mind, aura
|
* properties: strength, hardness, movement, skill, mind, aura
|
||||||
* drawinfo: x,y,w,h,col
|
* drawinfo: x,y,w,h,col
|
||||||
*/
|
*/
|
||||||
console.log("Creature called!");
|
|
||||||
this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"",
|
this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"",
|
||||||
"size":info["size"]*1};
|
"size":info["size"]*1};
|
||||||
console.log("Creature Ready!");
|
|
||||||
this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1,
|
this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1,
|
||||||
"spirit": attributes["spirit"]*1};
|
"spirit": attributes["spirit"]*1};
|
||||||
console.log("Problem?");
|
|
||||||
this.properties = {"strength": properties["strength"]*1 , "hardness": properties["hardness"]*1,
|
this.properties = {"strength": properties["strength"]*1 , "hardness": properties["hardness"]*1,
|
||||||
"movement": properties["movement"]*1, "skill": properties["skill"]*1,
|
"movement": properties["movement"]*1, "skill": properties["skill"]*1,
|
||||||
"mind": properties["mind"]*1, "aura": properties["aura"]*1};
|
"mind": properties["mind"]*1, "aura": properties["aura"]*1};
|
||||||
|
@ -102,12 +124,79 @@
|
||||||
this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill;
|
this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill;
|
||||||
};
|
};
|
||||||
this.life = this.battle["life"]*1;
|
this.life = this.battle["life"]*1;
|
||||||
|
this.att = "melee";
|
||||||
},
|
},
|
||||||
|
|
||||||
attack: function(enem) {
|
attack: function(enem) {
|
||||||
//console.log("attack");
|
clearui();
|
||||||
console.log(this.info.cname+" greift "+enem.info.cname+" an!");
|
var output=$('#output');
|
||||||
console.log("Ergebnis: " + this.battle.melee + ( this.battle.melee > enem.battle.defense ? " > " : " < ") + enem.battle.defense);
|
output.html(this.info.cname+" greift "+enem.info.cname+" an!<br>");
|
||||||
|
var attack_val = dice(this.battle[this.att]);
|
||||||
|
if (! attack_val ) {
|
||||||
|
output.append('Angriff Fehlgeschlagen!<br>');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
output.append(this.info.cname + " trifft mit " + attack_val + "<br>");
|
||||||
|
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!<br>");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output.append(enem.info.cname + " wehrt sich mit " + defense_val+".<br>");
|
||||||
|
}
|
||||||
|
if ( attack_val === 0 ) {
|
||||||
|
output.append("Vollständig Abgewehrt!<br>");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output.append("Schaden: "+attack_val+"<br>");
|
||||||
|
};
|
||||||
|
enem.life -= attack_val;
|
||||||
|
if( enem.life <= 0 ) {
|
||||||
|
if ( enem.enem ){
|
||||||
|
output.append(enem.info.cname + " ist besiegt<br>");
|
||||||
|
enem.die();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output.append(enem.info.cname + " ist bewusstlos<br>");
|
||||||
|
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?<br>";
|
||||||
|
outstr += "<select id='att'>";
|
||||||
|
outstr += "<option value='melee' id='melee'>Melee (" + this.battle["melee"] + ")</option>";
|
||||||
|
outstr += "<option value='shoot' id='shoot'>Schuss (" + this.battle["shoot"] + ")</option>";
|
||||||
|
outstr += "<option value='shoot_chant' id='shoot_chant'>Zielzauber (" +this.battle["shoot_chant"]
|
||||||
|
+")</option>";
|
||||||
|
outstr += "</select>";
|
||||||
|
$('#ui').html(outstr);
|
||||||
|
$('#att').bind("change", function() {cur_sel.att=this.value;});
|
||||||
|
$("#"+this.att).get(0).selected="true";
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var Player = Creature.extend({
|
var Player = Creature.extend({
|
||||||
|
@ -124,7 +213,6 @@
|
||||||
|
|
||||||
// Set default battle-propoerties.
|
// Set default battle-propoerties.
|
||||||
this.extern = {"armor":0,"chant":0,"weapon":0};
|
this.extern = {"armor":0,"chant":0,"weapon":0};
|
||||||
console.log(this.battle.defense);
|
|
||||||
this.battle.defense += this.extern.armor;
|
this.battle.defense += this.extern.armor;
|
||||||
this.battle.melee += this.extern.weapon;
|
this.battle.melee += this.extern.weapon;
|
||||||
this.battle.shoot += this.extern.weapon;
|
this.battle.shoot += this.extern.weapon;
|
||||||
|
@ -132,8 +220,13 @@
|
||||||
this.battle.shoot_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() {
|
printoutput: function() {
|
||||||
$('#output').empty();
|
outstr = "";
|
||||||
$('#output').html(this.info.cname+"<br>"+this.info.pname);
|
outstr += this.info.cname + " (gespielt von "+this.info.pname +")<br>";
|
||||||
|
outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von "
|
||||||
|
+ this.battle[this.att] + " an.<br>";
|
||||||
|
outstr += "Verteidigungsstärke: " + this.battle.defense + "<br>";
|
||||||
|
outstr += "Kraftpunkte: " + this.life;
|
||||||
|
$('#output').html(outstr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -148,10 +241,17 @@
|
||||||
|
|
||||||
this._super(info,attributes,properties,drawinfo,battle);
|
this._super(info,attributes,properties,drawinfo,battle);
|
||||||
this.info.cname=this.info.pname;
|
this.info.cname=this.info.pname;
|
||||||
|
this.enem = true;
|
||||||
},
|
},
|
||||||
printoutput: function() {
|
printoutput: function() {
|
||||||
$('#output').empty();
|
clearui();
|
||||||
$('#output').html(this.info.race+"<br>"+this.info.pname);
|
outstr = "";
|
||||||
|
outstr += "Ein "+ this.info.race + "<br>";
|
||||||
|
outstr += "Greift derzeit durch " + this.att + " mit einer Stärke von "
|
||||||
|
+ this.battle[this.att] + " an.<br>";
|
||||||
|
outstr += "Verteidigungsstärke: " + this.battle.defense + "<br>";
|
||||||
|
outstr += "Kraftpunkte: " + this.life;
|
||||||
|
$('#output').html(outstr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,15 @@
|
||||||
this.enableControl();
|
this.enableControl();
|
||||||
};
|
};
|
||||||
if(e.mouseButton === Crafty.mouseButtons.RIGHT) {
|
if(e.mouseButton === Crafty.mouseButtons.RIGHT) {
|
||||||
|
if ( !cur_sel ) { return; };
|
||||||
|
if ( cur_sel == player[this.id] )
|
||||||
|
{
|
||||||
|
cur_sel.sel_att();
|
||||||
|
}
|
||||||
|
else {
|
||||||
cur_sel.attack(player[this.id]);
|
cur_sel.attack(player[this.id]);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue