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

Assignment #9: Files and strings #6

Open
wants to merge 1 commit 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
44 changes: 44 additions & 0 deletions diceout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


DICE SET #1: 20:loaded:6 10:numbered 6:fudge 10:fudge 20:fudge
Create LOADED with 20 sides. Loaded number:6
Create NUMBERED die with 10 sides.
Create FUDGE with 6 sides.
ERROR: Number of sides (10) for Fudge die not allowed. Die not rolled.
ERROR: Number of sides (20) for Fudge die not allowed. Die not rolled.
Tray value for dice set #1: 8


DICE SET #2: 4:loaded:1 10:numbered 6:fudge 100:numbered 5:numbered
Create LOADED with 4 sides. Loaded number:1
Create NUMBERED die with 10 sides.
Create FUDGE with 6 sides.
Create NUMBERED die with 100 sides.
Create NUMBERED die with 5 sides.
Tray value for dice set #2: 11


DICE SET #3: 8:fudge 8:numbered 8:loaded:4
ERROR: Number of sides (8) for Fudge die not allowed. Die not rolled.
Create NUMBERED die with 8 sides.
Create LOADED with 8 sides. Loaded number:4
Tray value for dice set #3: 9


DICE SET #4: 10:numbered 10:numbered 10:numbered 10:numbered
Create NUMBERED die with 10 sides.
Create NUMBERED die with 10 sides.
Create NUMBERED die with 10 sides.
Create NUMBERED die with 10 sides.
Tray value for dice set #4: 24


DICE SET #5: 6:fudge 6:loaded:2 6:loaded:4 6:loaded:6
Create FUDGE with 6 sides.
Create LOADED with 6 sides. Loaded number:2
Create LOADED with 6 sides. Loaded number:4
Create LOADED with 6 sides. Loaded number:6
Tray value for dice set #5: 7


That's all folks!
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\\srtinkey\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
2 changes: 1 addition & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=assignment.pkg9.DiceReaderDriver
main.class=assignment.pkg9.DnDDiceRoller
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
21 changes: 15 additions & 6 deletions src/assignment/pkg9/DiceFileReader.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg9;

import java.io.File;
Expand Down Expand Up @@ -45,6 +40,20 @@ public List<String> getLines(){

public void read(){
this.lines = new ArrayList();
// Put you read logic and populate lines

while(this.input.hasNext()) {
try {
String fileLine = this.input.nextLine();
// skip comment lines that begin with #
if (fileLine.charAt(0) != '#') {
this.lines.add(fileLine);
}
}
catch (Exception e){
System.out.println("Error reading next line in file");
System.out.println(e.getMessage());
}
}
input.close(); // close file
}
}
5 changes: 0 additions & 5 deletions src/assignment/pkg9/DiceReaderTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg9;

/**
Expand Down
70 changes: 70 additions & 0 deletions src/assignment/pkg9/DiceTower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package assignment.pkg9;

import java.util.ArrayList;
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 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 Sharon R. Tinkey
*/

public class DiceTower {
final int PANEL_COUNT = 3; // number of panels in dice tower
List<Die> dice; // arraylist of die objects of varying classes
private int dieNum; // number rolled by a die
private int trayValue; // value of all dice rolled

/**
* constructor
* no params
*/
public DiceTower() {
this.dice = new ArrayList();
dieNum = 0;
trayValue = 0;
}

/**
* constructor
* @param dice arraylist of die objects
*/
public DiceTower(List dice) {
this.dice = dice;
dieNum = 0;
trayValue = 0;
}

/**
* dropDice drop die objects in arraylist through dice tower to roll
* no params uses class fields
* returns nothing
*/
public void dropDice(){
// roll the dice as many times as there are panels in dice tower
for (int cubes = 0; cubes < dice.size(); cubes++){
for (int rolls = 0; rolls < PANEL_COUNT; rolls++) {
this.dice.get(cubes).roll();
}
trayValue += this.dice.get(cubes).getDieValue();
// System.out.println("Roll die with " + this.dice.get(cubes).getDieSides() +
// " sides - Value: " + this.dice.get(cubes).getDieValue());
}
}

/**
* trayValue adds together the roll results of die objects in arraylist
* @return sum of roll results
*/
public int trayValue(){
// return sum of values of dice
return trayValue;
}
}
12 changes: 12 additions & 0 deletions src/assignment/pkg9/Die.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package assignment.pkg9;

/**
* Interface for all die types
*
* @author srtinkey
*/
public interface Die {
public int getDieSides();
public int getDieValue();
public void roll();
}
Loading