From d982b33f918e65bdfae10ad82f49fab2353567ed Mon Sep 17 00:00:00 2001 From: stevenPlas Date: Mon, 19 Oct 2015 17:59:43 -0400 Subject: [PATCH 1/2] Arrays Completed assignment. --- src/dnddiceroller/DiceTower.java | 31 ++++++++++++++++++--------- src/dnddiceroller/Die.java | 32 ++++++++++++++++++++++------ src/dnddiceroller/DnDDiceRoller.java | 7 +++--- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/dnddiceroller/DiceTower.java b/src/dnddiceroller/DiceTower.java index 198514f..c306678 100644 --- a/src/dnddiceroller/DiceTower.java +++ b/src/dnddiceroller/DiceTower.java @@ -4,25 +4,36 @@ 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 int dieSum; public DiceTower() { this.dice = new ArrayList(); + dieSum = 0; } - public DiceTower(List dice) { + public DiceTower(List dice){ this.dice = dice; + dieSum = 0; } + + public int getDieSum(){ + return 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..bf4efe5 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 double getValue() { + return this.value; + } + + + public void roll(){ + Random rand = new Random(); + 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{ From 04b8d4d397e3908f35f40bf61f4bf5263859a636 Mon Sep 17 00:00:00 2001 From: stevenPlas Date: Wed, 21 Oct 2015 16:17:59 -0400 Subject: [PATCH 2/2] Small fixes Fixed some variable problems --- src/dnddiceroller/DiceTower.java | 15 ++++++++------- src/dnddiceroller/Die.java | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/dnddiceroller/DiceTower.java b/src/dnddiceroller/DiceTower.java index c306678..2f9a47d 100644 --- a/src/dnddiceroller/DiceTower.java +++ b/src/dnddiceroller/DiceTower.java @@ -7,27 +7,28 @@ * @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(); - dieSum = 0; + this.dieSum = 0; } public DiceTower(List dice){ this.dice = dice; - dieSum = 0; + this.dieSum = 0; } public int getDieSum(){ - return dieSum; + return this.dieSum; } public void dropDice() { - int i = 0; - for (Die die : dice){ + + int i = 0; + for (Die die : dice){ dice.stream().forEach((_item) -> { die.roll(); diff --git a/src/dnddiceroller/Die.java b/src/dnddiceroller/Die.java index bf4efe5..62302be 100644 --- a/src/dnddiceroller/Die.java +++ b/src/dnddiceroller/Die.java @@ -13,19 +13,19 @@ public class Die { * * @param Sides */ - public Die(int Sides) { - this.sides = Sides; + public Die(int sides) { + this.sides = sides; } - public double getValue() { + public int getValue() { return this.value; } public void roll(){ Random rand = new Random(); - value = rand.nextInt(this.sides) + 1; + this.value = rand.nextInt(this.sides) + 1; } }