package Keeproll; import java.util.Random; public class result { private StringBuilder text; private int value; private final int diceart; private Boolean reroll9; private Boolean reroll1; private Boolean maxReroll; private Boolean noreroll; public result() { diceart = 10; text = new StringBuilder(); value = 0; reroll9 = false; reroll1 = false; maxReroll = false; noreroll = false; } public String getText() { return text.toString(); } public void setText(String text) { this.text = new StringBuilder(); this.text.append(text); } public void setMarket() { String tmp = this.text.toString(); this.text = new StringBuilder(); this.text.append("**").append(tmp).append("**"); } public int getValue() { return value; } public void setValue(Integer value) { this.value = value; } public result setReroll9(Boolean reroll9) { this.reroll9 = reroll9; return this; } public result setReroll1(Boolean reroll1) { this.reroll1 = reroll1; return this; } public result setMaxReroll(Boolean maxReroll) { this.maxReroll = maxReroll; return this; } public result setNoreroll(Boolean noreroll) { this.noreroll = noreroll; return this; } public result roll() { int dice; int rolls = 0; Boolean reroll = false; do{ reroll = false; dice = new Random().nextInt(diceart); dice++; if(text.length() > 0) { text.append("+"); } if(reroll1 && dice == 1 && rolls <= 0) { text.append("~~ ").append(dice).append(" ~~ "); } else { text.append(dice); } value += dice; if(!noreroll) { if (dice == 10) { reroll = rolls <= 0 || !maxReroll; // wenn maxRolls an und schon einmal gerollt wurde kein reroll ++rolls; } else if (reroll9 && dice == 9) { reroll = rolls <= 0 || !maxReroll; } else if (reroll1 && dice == 1 && rolls <= 0) { reroll = true; value--; } } } while(reroll); return this; } }