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

Tentative Commit #8

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
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\\User\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
15 changes: 15 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceReaderTest.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/NumberedDie.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceFileReader.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/Die.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceTower.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DnDDiceRoller.java</file>
<file>file:/C:/Users/User/Documents/Programming/Java%20Programming/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/Loaded.java</file>
</group>
</open-files>
</project-private>
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
Empty file added results.txt
Empty file.
8 changes: 7 additions & 1 deletion src/assignment/pkg9/DiceFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public List<String> getLines(){

public void read(){
this.lines = new ArrayList();
// Put you read logic and populate lines
//Skips the comments in the input file
while (this.input.hasNext()){
String line = this.input.nextLine();
if (line.charAt(0) != '#') {
this.lines.add(line);
}
}
}
}
49 changes: 45 additions & 4 deletions src/assignment/pkg9/DiceReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
*/
package assignment.pkg9;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Paul Scarrone
Expand All @@ -14,9 +21,43 @@
// Once you are done with reading and calculating dice you will need to update
// this test to pass again
public class DiceReaderTest {
public static void test_reader(){
DiceFileReader diceReader = new DiceFileReader("dice.txt");
public static void test_reader() throws FileNotFoundException{
DiceFileReader diceReader = new DiceFileReader("./dice.txt");
diceReader.read();
System.out.println(diceReader.getLines().toString().equals("[]"));
}

PrintWriter writer = new PrintWriter("./results.txt");
Copy link
Member

Choose a reason for hiding this comment

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

I think its better if PrintWritter is backed by a FileWriter


List<String> basicFile = new ArrayList<>();
basicFile = diceReader.getLines();
for (int i = 0; i < basicFile.size(); i++){
String[] fileLine = basicFile.get(i).split(" ");

for (int x = 0; x < fileLine.length; x++){
String[] indivDie = fileLine[x].split(":");

int sides = Integer.parseInt(indivDie[0]);
String type = indivDie[1];
int loadedSides = 0;

if (type.equals("loaded")){
Copy link
Member

Choose a reason for hiding this comment

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

good use of equals

loadedSides = Integer.parseInt(indivDie[2]);
Loaded loadedDie = new Loaded(sides, loadedSides);
loadedDie.roll();
writer.write(fileLine[i] + ": Loaded, " + loadedDie.getValue());
}else if (type.equals("numbered")){
NumberedDie numberedDie = new NumberedDie(sides);
numberedDie.roll();
writer.write(fileLine[i] + ": Numbered, " + numberedDie.getValue());
}else if (type.equals("fudge")){
Fudge fudgedDie = new Fudge(sides);
fudgedDie.roll();
writer.write(fileLine[i] + ": Fudge, " + fudgedDie.getValue());
}

}
writer.close();

}
System.out.println(diceReader.getLines().toString().equals("[]"));
}
}
53 changes: 53 additions & 0 deletions src/assignment/pkg9/DiceTower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 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
*/
public class DiceTower {
final int PANEL_COUNT = 3;
List<Die> dice;
int trayValue;

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

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

public int getTrayValue() {
return trayValue;
}


/**
* Utilizes the roll() method per the number of panels in the dice tower.
*/
public void dropDice() {
int i = 0;
for (Die die : dice){
for(int x = 0; x < PANEL_COUNT; x++){
dice.get(i).roll();
}
trayValue += dice.get(i).getValue();
i++;
}
}


}

15 changes: 15 additions & 0 deletions src/assignment/pkg9/Die.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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;

/**
*
* @author User
*/
public interface Die {
public void roll();
public int getValue();
}
56 changes: 56 additions & 0 deletions src/assignment/pkg9/DnDDiceRoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package assignment.pkg9;

import static assignment.pkg9.DiceReaderTest.test_reader;
import java.util.ArrayList;
import java.util.List;

/**
*
* @author Paul Scarrone
*/
public class DnDDiceRoller {

/**
* Try out your dies and dice tower
* @param args the command line arguments
*/
public static void main(String[] args) {
for(int i = 0; i< 1000; i++){
int d6 = test_oneD6();
if(d6 != -1){
System.out.println("Die Test Failed with Value: " + d6);
}
int tower = test_diceTowerWithTwoD6();
if(tower != -1){
System.out.println("Tower Test Failed with Value: " + tower);
}
}

}

public static int test_oneD6(){
NumberedDie die = new NumberedDie(6);
die.roll();
int dieValue = die.getValue();
if(dieValue >= 1 && dieValue <= 6){
return -1; // Means the die value is inside its bounds for a d6
}else{
return dieValue;
}
}

public static int test_diceTowerWithTwoD6(){
List<NumberedDie> dice = new ArrayList();
dice.add(new NumberedDie(6));
dice.add(new NumberedDie(6));
DiceTower tower = new DiceTower(dice);
tower.dropDice();
int trayValue = tower.getTrayValue();
if(trayValue >= 2 && trayValue <= 12){
return -1; // means the die value is outside the bounds of 2 d6
}else{
return trayValue;
}
}

}
35 changes: 35 additions & 0 deletions src/assignment/pkg9/Fudge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.util.Random;

/**
*
* @author User
*/
public class Fudge implements Die {
private int sides;
private int value;

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

@Override
public int getValue() {
return value;
}

/**
* Method that updates the value field with either -1, 1, or 0.
*/
@Override
public void roll(){
Random rand = new Random();
this.value = rand.nextInt(3) - 1;
}
}
41 changes: 41 additions & 0 deletions src/assignment/pkg9/Loaded.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.util.Random;

/**
*
* @author User
*/
public class Loaded implements Die {
private int sides;
private int loadedSides;
private int value;

public Loaded(int sides, int loadedSides){
this.sides = sides;
this.loadedSides = loadedSides;
}

@Override
public int getValue() {
return value;
}

/**
* Method that updates the value field until it rolls the maximum number.
*/
@Override
public void roll(){
Random rand = new Random();
this.value = rand.nextInt(this.sides) + 1;
while(this.value != this.sides + 1){
rand = new Random();
this.value = rand.nextInt(this.sides) + 1;
}
}
}
31 changes: 31 additions & 0 deletions src/assignment/pkg9/NumberedDie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package assignment.pkg9;

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
*/
public class NumberedDie implements Die {
private int sides;
private int value;

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

public int getValue() {
return value;
}

/**
* Method that updates the value field with a random number within a scope.
*/
public void roll(){
Random rand = new Random();
this.value = rand.nextInt(this.sides) + 1;
}
}