-
Notifications
You must be signed in to change notification settings - Fork 14
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
DTkach
wants to merge
1
commit into
WCCCEDU:master
Choose a base branch
from
DTkach:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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"); | ||
|
||
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")){ | ||
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. 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("[]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think its better if PrintWritter is backed by a FileWriter