Sheet.java
jmud-0.11/src/Sheet.java · 1.4 KB
From the archive jmud-0_11.tgz
Download the archive « Back to the archive contents
class Sheet {
static private Dice d10 = new Dice(10);
static private final int THRESHOLD = 4; // tab[4] = 8
static private int difficultyTab[] = {
4, // 0
5,
6,
7,
8, // 4 => THRESHOLD
9,
11,
15,
18,
19,
23,
27,
29,
31,
36,
39,
41,
45,
48,
49,
53,
57,
59,
61,
66,
69,
71,
75,
78,
79,
83,
87,
89,
91,
96,
99
};
static public int getDifficulty(int difference) {
if (difference < -9)
return 1;
if (difference < -2)
return 2;
if (difference < 0)
return difference + 4;
if (difference >= difficultyTab.length)
return 100;
return difficultyTab[difference];
}
static public int getBonus(int result, int difference) {
int i = (THRESHOLD > difference) ? THRESHOLD : difference;
while (i < difficultyTab.length && result >= difficultyTab[i])
++i;
return i - THRESHOLD;
}
static public int getEffect(int difference, int bonus) {
difference += bonus;
return difference < 0 ? 0 : difference + 1;
}
static public int roll(int difficulty) {
final int FALHA = 0;
final int CRITICA = -1;
d10.roll();
if (d10.getFace() == 1)
return (d10.roll() == 1) ? ((difficulty == 1) ? FALHA : CRITICA) : FALHA;
int result = d10.getFace();
while (d10.getFace() == 10)
result += d10.roll();
return result;
}
}