Attack now only misses range-stuff

This commit is contained in:
Oliver Rümpelein 2014-09-25 15:23:54 +02:00
parent 3a37375cf2
commit c419d6c2cf
2 changed files with 94 additions and 13 deletions

View file

@ -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();});
});

View file

@ -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!<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>";
@ -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+"<br>"+this.info.pname);
outstr = "";
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);
}
});
@ -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+"<br>"+this.info.pname);
clearui();
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);
}
});
}