Merge branch 'master' into doc
This commit is contained in:
commit
12d5139256
2 changed files with 31 additions and 11 deletions
1
TODO
1
TODO
|
@ -7,7 +7,6 @@ ToDo for JSDSH:
|
|||
- second adventure
|
||||
- add avatars for players and monsters
|
||||
- attack distance
|
||||
- Testvalues > 20
|
||||
- Objects: Pass object to initializer
|
||||
- Hitbox on "things"
|
||||
- Instructions-page
|
||||
|
|
41
src/jsds.js
41
src/jsds.js
|
@ -83,19 +83,40 @@
|
|||
// Not yet implemented: Tests for values larger than 20
|
||||
// 1
|
||||
var dice = function(probe) {
|
||||
var diceval = Math.floor(Math.random() * (21 - 1)) + 1;
|
||||
if ( diceval <= probe ) {
|
||||
return diceval;
|
||||
}
|
||||
else {
|
||||
if (diceval === 20) {
|
||||
alert ("Patzer!"); // We need alert here, because most "Patzer"
|
||||
// affect gameplay (dropping equipement and so on)
|
||||
};
|
||||
var diceval=new Array();
|
||||
var rolls=Math.floor(probe/20)+1; // Player may be allowed to roll the dice several times.
|
||||
var tvalues=new Array();
|
||||
var result=0;
|
||||
var tmpval;
|
||||
for(var i=0; i<rolls; ++i) {
|
||||
diceval.push(Math.floor(Math.random() * (21 - 1)) + 1);
|
||||
tvalues.push(20);
|
||||
};
|
||||
console.log(diceval);
|
||||
tvalues[rolls-1]=probe%20; //the last value is the lowest
|
||||
if (diceval[0]===20) {
|
||||
alert ("Patzer!");
|
||||
return 0;
|
||||
};
|
||||
diceval.sort(function(a,b){
|
||||
if(a===1) return -1;
|
||||
if(b===1) return 1;
|
||||
return b-a;}
|
||||
);
|
||||
console.log(diceval);
|
||||
for(var i=0; i<rolls-1; ++i) { //First, evaluate the testvalues "20", that is each except the last one
|
||||
tmpval=diceval[i];
|
||||
result+= (tmpval == 1)?20:tmpval; //If result of dice is "1", return maximum.
|
||||
};
|
||||
tmpval=diceval[rolls-1];
|
||||
testval=tvalues[rolls-1];
|
||||
if(tmpval <= testval){
|
||||
result+= (tmpval ==1)?tvalues[rolls-1]:tmpval;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// Own Classes for Creatures, derived from the Basic Object class from above
|
||||
|
||||
// Creature is the base class for every "living" (or dead) "being"
|
||||
|
@ -161,7 +182,7 @@
|
|||
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 ) {
|
||||
if (attack_val == 0 ) {
|
||||
output.append('Angriff Fehlgeschlagen!<br>');
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue