diff --git a/src/dnddiceroller/DiceTower.java b/src/dnddiceroller/DiceTower.java index 198514f..2f9a47d 100644 --- a/src/dnddiceroller/DiceTower.java +++ b/src/dnddiceroller/DiceTower.java @@ -4,25 +4,37 @@ import java.util.List; /** - * Dice Tower. - * A Dice Tower is a tool used by serious gamers use to roll many dice at once. - * It looks like this https://www.miniaturescenery.com/Images/PortableDiceTowerLarge.jpg - * An instance of a dice tower is defined by the number panels it contains to help - * provide a more regular distribution of die values. The die bounce from panel to - * panel until they exit the dice tower at the bottom tray. - * A dice tower will accept a collection of dice and reports their results when - * they reach the tray at the bottom - * @author Paul Scarrone + * @author Steven Plas */ public class DiceTower { - final int PANEL_COUNT = 3; - List dice; + private final int PANEL_COUNT = 3; + private List dice; + private int dieSum; public DiceTower() { this.dice = new ArrayList(); + this.dieSum = 0; } - public DiceTower(List dice) { + public DiceTower(List dice){ this.dice = dice; + this.dieSum = 0; } + + public int getDieSum(){ + return this.dieSum; + } + + public void dropDice() { + + int i = 0; + for (Die die : dice){ + + dice.stream().forEach((_item) -> { + die.roll(); + }); + dieSum += dice.get(i).getValue(); + i++; + } + } } diff --git a/src/dnddiceroller/Die.java b/src/dnddiceroller/Die.java index 2004a47..62302be 100644 --- a/src/dnddiceroller/Die.java +++ b/src/dnddiceroller/Die.java @@ -1,12 +1,32 @@ package dnddiceroller; +import java.util.Random; /** - * A Die is a many sided object that when rolled provides a random value from - * 1 through the number of sides on the object. Some dice are 6 sided and have - * the numbers 1-6 on them. Some dice are 20 sided with the numbers 1-20 on them. - * Others are called fudge dice and have the values of -1 0 or +1 - * @author Paul Scarrone + * @author Steven Plas */ public class Die { - + + private final int sides; + private int value; + + /** + * + * @param Sides + */ + public Die(int sides) { + this.sides = sides; + + } + + public int getValue() { + return this.value; + } + + + public void roll(){ + Random rand = new Random(); + this.value = rand.nextInt(this.sides) + 1; + } + } + diff --git a/src/dnddiceroller/DnDDiceRoller.java b/src/dnddiceroller/DnDDiceRoller.java index c957d38..b818cd4 100644 --- a/src/dnddiceroller/DnDDiceRoller.java +++ b/src/dnddiceroller/DnDDiceRoller.java @@ -1,5 +1,6 @@ package dnddiceroller; + import java.util.ArrayList; import java.util.List; @@ -29,7 +30,7 @@ public static void main(String[] args) { public static int test_oneD6(){ Die die = new Die(6); die.roll(); - int dieValue = die.value(); + int dieValue = (int) die.getValue(); if(dieValue >= 1 && dieValue <= 6){ return -1; // Means the die value is outside its bounds for a d6 }else{ @@ -41,9 +42,9 @@ public static int test_diceTowerWithTwoD6(){ List dice = new ArrayList(); dice.add(new Die(6)); dice.add(new Die(6)); - DiceTower tower = DiceTower(dice); + DiceTower tower = new DiceTower(dice); tower.dropDice(); - int trayValue = tower.trayValue(); + int trayValue = tower.getDieSum(); if(trayValue >= 2 && trayValue <= 12){ return -1; // means the die value is outside the bounds of 2 d6 }else{