Dice-function is complete, this includes:
- Test-values larger than 20 - "1" is an ever-success - "20" in first roll is an ultimate failure
This commit is contained in:
parent
108936324c
commit
ce9f06a864
1 changed files with 30 additions and 16 deletions
46
src/jsds.js
46
src/jsds.js
|
@ -82,26 +82,40 @@
|
||||||
// Probe-Function: checks, whether a given "effort" is succesfull, according to the rules of DS
|
// Probe-Function: checks, whether a given "effort" is succesfull, according to the rules of DS
|
||||||
// Not yet implemented: Tests for values larger than 20
|
// Not yet implemented: Tests for values larger than 20
|
||||||
var dice = function(probe) {
|
var dice = function(probe) {
|
||||||
console.log(probe);
|
var diceval=new Array();
|
||||||
var diceval = Math.floor(Math.random() * (21 - 1)) + 1;
|
var rolls=Math.floor(probe/20)+1; // Player may be allowed to roll the dice several times.
|
||||||
if ( diceval <= probe ) {
|
var tvalues=new Array();
|
||||||
if (diceval == 1) {
|
var result=0;
|
||||||
alert ("Immersieg!");
|
var tmpval;
|
||||||
return probe;
|
for(var i=0; i<rolls; ++i) {
|
||||||
}
|
diceval.push(Math.floor(Math.random() * (21 - 1)) + 1);
|
||||||
else {
|
tvalues.push(20);
|
||||||
return diceval;
|
};
|
||||||
};
|
console.log(diceval);
|
||||||
}
|
tvalues[rolls-1]=probe%20; //the last value is the lowest
|
||||||
else {
|
if (diceval[0]===20) {
|
||||||
if (diceval === 20) {
|
alert ("Patzer!");
|
||||||
alert ("Patzer!"); // We need alert here, because most "Patzer"
|
|
||||||
// affect gameplay (dropping equipement and so on)
|
|
||||||
};
|
|
||||||
return 0;
|
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
|
// Own Classes for Creatures, derived from the Basic Object class from above
|
||||||
|
|
||||||
// Creature is the base class for every "living" (or dead) "being"
|
// Creature is the base class for every "living" (or dead) "being"
|
||||||
|
|
Loading…
Reference in a new issue