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

Dice Roller Program that checks itself for validity. #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
dist/
/Assignment7-Array-DiceTower/nbproject/private/
2 changes: 1 addition & 1 deletion nbproject/private/private.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
compile.on.save=true
user.properties.file=/Users/samuraipanzer/Library/Application Support/NetBeans/8.0.2/build.properties
user.properties.file=C:\\Users\\Tehold\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
11 changes: 11 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/Tehold/Documents/NetBeansProjects/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/DnDDiceRoller.java</file>
<file>file:/C:/Users/Tehold/Documents/NetBeansProjects/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/DiceTower.java</file>
<file>file:/C:/Users/Tehold/Documents/NetBeansProjects/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/Die.java</file>
</group>
</open-files>
</project-private>
29 changes: 27 additions & 2 deletions src/dnddiceroller/DiceTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

/**
* Dice Tower.
Expand All @@ -15,14 +16,38 @@
* @author Paul Scarrone
*/
public class DiceTower {
final int PANEL_COUNT = 3;
List<Die> dice;
private final int PANEL_COUNT = 3;
private int tray;
private List<Die> dice;

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

public DiceTower(List dice) {
this.dice = dice;
this.tray = 0;
}

public void dropDice(){
for(int sides = 0; sides < this.PANEL_COUNT; sides++){
for(Die droppedDie: this.dice){
droppedDie.roll();
}
}
}

/**
* Returns the value of all dice in the tray
* @return Tray Value
*/
public int trayValue(){
this.tray = 0;
for(Die die: dice){
this.tray += die.value();
}
return this.tray;
}

}
28 changes: 27 additions & 1 deletion src/dnddiceroller/Die.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
Expand All @@ -8,5 +10,29 @@
* @author Paul Scarrone
*/
public class Die {

private int value;
private int sides;

public Die(){
this.sides = 0;
}

public Die(int sides){
this.sides = sides;
}

/**
* Returns the value of a die
* @return Die Value
*/
public int value(){
return this.value;
}

/**
* Method to "roll" a die and set its value equal to a random number
*/
public void roll(){
this.value = (new Random()).nextInt(this.sides) +1;
}
}
4 changes: 2 additions & 2 deletions src/dnddiceroller/DnDDiceRoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public static int test_oneD6(){
}

public static int test_diceTowerWithTwoD6(){
List<Die> dice = new ArrayList();
ArrayList<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();
if(trayValue >= 2 && trayValue <= 12){
Expand Down