Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/dnddiceroller/DiceTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

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

private int dieSum;

public DiceTower() {
this.dice = new ArrayList();
dieSum = 0;
}

public DiceTower(List dice) {
public DiceTower(List dice){
this.dice = dice;
dieSum = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is expected since it is a field

}

public int getDieSum(){
return dieSum;
}

public void dropDice() {
int i = 0;
for (Die die : dice){
Copy link
Member

Choose a reason for hiding this comment

The 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) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH YEA STREAMS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your use of streams!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you guys!

die.roll();
});
dieSum += dice.get(i).getValue();
i++;
}
}
}
32 changes: 26 additions & 6 deletions src/dnddiceroller/Die.java
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sides should not be capitalized. Class names are capitalized.

Copy link
Author

Choose a reason for hiding this comment

The 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a double? when this.value is an int

Copy link
Author

Choose a reason for hiding this comment

The 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be this.value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. I am definitely tired tonight.

}

}

7 changes: 4 additions & 3 deletions src/dnddiceroller/DnDDiceRoller.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dnddiceroller;


import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -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{
Expand All @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice opinionated change to the expected api

Copy link
Author

Choose a reason for hiding this comment

The 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{
Expand Down