-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arrays #2
base: master
Are you sure you want to change the base?
Arrays #2
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Die> 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public int getDieSum(){ | ||
return dieSum; | ||
} | ||
|
||
public void dropDice() { | ||
int i = 0; | ||
for (Die die : dice){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is a double loop. For each die on :30 you roll all the dice again meaning their values keep changing |
||
|
||
dice.stream().forEach((_item) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OH YEA There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your use of streams! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks you guys! |
||
die.roll(); | ||
}); | ||
dieSum += dice.get(i).getValue(); | ||
i++; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. I just happened to type that on accident:/ |
||
this.sides = Sides; | ||
|
||
} | ||
|
||
public double getValue() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this a double? when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I messed up when i was writing it, and accidentally wrote double some how. I am fixing this now. |
||
return this.value; | ||
} | ||
|
||
|
||
public void roll(){ | ||
Random rand = new Random(); | ||
value = rand.nextInt(this.sides) + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This what? I don't see the problem. I could be reading it wrong though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be this.value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow. I am definitely tired tonight. |
||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Die> 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice opinionated change to the expected api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like being different than other people every once and a while lol. |
||
if(trayValue >= 2 && trayValue <= 12){ | ||
return -1; // means the die value is outside the bounds of 2 d6 | ||
}else{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be private too