mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
First commit
Former-commit-id: 9340873f9cfb15264004c32d6e4b8f8bd6828d94 Former-commit-id: 1916747c109876aa064412e01204c3aeda9bbbc0
This commit is contained in:
42
src/com/Torvald/Rand/FudgeDice.java
Normal file
42
src/com/Torvald/Rand/FudgeDice.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.Torvald.Rand;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-03.
|
||||
*/
|
||||
public class FudgeDice {
|
||||
|
||||
private Random randfunc;
|
||||
private int diceCounts;
|
||||
|
||||
/**
|
||||
* Define new set of fudge dice with given counts.
|
||||
* @param randfunc
|
||||
* @param counts amount of die
|
||||
*/
|
||||
public FudgeDice(Random randfunc, int counts) {
|
||||
this.randfunc = randfunc;
|
||||
diceCounts = counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll dice and get result. Range: [-3, 3] for three dice
|
||||
* @return
|
||||
*/
|
||||
public int roll() {
|
||||
int diceResult = 0;
|
||||
for (int c = 0; c < diceCounts; c++) {
|
||||
diceResult += rollSingleDie();
|
||||
}
|
||||
|
||||
return diceResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return random [-1, 0, 1]
|
||||
*/
|
||||
private int rollSingleDie() {
|
||||
return (randfunc.nextInt(3)) - 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user