-
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
Initial Commit #13
Open
Paa1006
wants to merge
1
commit into
WCCCEDU:master
Choose a base branch
from
Paa1006:Paa1006-Assignment9
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
Initial Commit #13
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Loaded:18 | ||
Numbered:4 | ||
Fudged:-1 | ||
Fudged:0 | ||
Fudged:-1 | ||
----------END OF SET------------ | ||
Loaded:1 | ||
Numbered:6 | ||
Fudged:1 | ||
Numbered:15 | ||
Numbered:5 | ||
----------END OF SET------------ | ||
Fudged:0 | ||
Numbered:6 | ||
Loaded:8 | ||
----------END OF SET------------ | ||
Numbered:2 | ||
Numbered:2 | ||
Numbered:5 | ||
Numbered:2 | ||
----------END OF SET------------ | ||
Fudged:1 | ||
Loaded:6 | ||
Loaded:4 | ||
Loaded:2 | ||
----------END OF SET------------ |
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 |
---|---|---|
@@ -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 |
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,12 @@ | ||
<?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/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceReaderTest.java</file> | ||
<file>file:/C:/Users/Tehold/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceFileReader.java</file> | ||
<file>file:/C:/Users/Tehold/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/DiceTower.java</file> | ||
<file>file:/C:/Users/Tehold/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/DnDDiceRoller.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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dnddiceroller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* 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 { | ||
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; | ||
} | ||
|
||
} |
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,29 @@ | ||
/* | ||
* 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 dnddiceroller; | ||
|
||
/** | ||
* | ||
* @author Tehold | ||
*/ | ||
public interface Die { | ||
/** | ||
* Returns value of a Die | ||
* @return integer Value of Die | ||
*/ | ||
public int value(); | ||
/** | ||
* Returns name of Die | ||
* @return type of Die | ||
*/ | ||
public String name(); | ||
/** | ||
* Roll method to simulate rolling a Die | ||
* And setting value to a random integer | ||
*/ | ||
public void roll(); | ||
|
||
} |
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,85 @@ | ||
package dnddiceroller; | ||
|
||
import assignment.pkg9.DiceFileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* | ||
* @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) { | ||
//ArrayList that will hold our dice | ||
ArrayList<Die> dieList = new ArrayList(); | ||
|
||
// Send file to DiceFileReader and have it process the file | ||
// Then assign that information to the lines ArrayList; | ||
DiceFileReader fileReader = new DiceFileReader("dice.txt"); | ||
fileReader.read(); | ||
ArrayList<String> lines = fileReader.getLines(); | ||
|
||
// Access each line one at a time | ||
for (String singleLine : lines) | ||
{ | ||
// Split line at spaces | ||
String[] spaceTokens = singleLine.split(" "); | ||
// Access each die information one at a time | ||
for (String dieTokens: spaceTokens) | ||
{ | ||
// Split line at colons | ||
String[] colonTokens = dieTokens.split(":"); | ||
// Declare variables that will be used to create different Dies | ||
Integer sides; | ||
Integer loadedSide; | ||
// Switch statement based on type of die that creates a Die in the | ||
// ArrayList | ||
switch (colonTokens[1]) { | ||
case "numbered": | ||
sides = Integer.parseInt(colonTokens[0]); | ||
dieList.add(new NumberedDie(sides)); | ||
break; | ||
case "fudge": | ||
sides = Integer.parseInt(colonTokens[0]); | ||
dieList.add(new FudgedDie(sides)); | ||
break; | ||
default: | ||
sides = Integer.parseInt(colonTokens[0]); | ||
loadedSide = Integer.parseInt(colonTokens[2]); | ||
dieList.add(new LoadedDie(sides, loadedSide)); | ||
break; | ||
} // End Switch that Assigns Die ArrayList | ||
} // End For that breaks each token at colons | ||
|
||
// Create Dice tower and give it the Array List and have it drop dice | ||
DiceTower diceTower = new DiceTower(dieList); | ||
diceTower.dropDice(); | ||
|
||
// Create a FileWriter object to save output | ||
try{ | ||
FileWriter rolledDice = new FileWriter("Output.txt", true); | ||
PrintWriter outputFile = new PrintWriter(rolledDice); | ||
// Step Through each Die in Array and Output info to file | ||
for(Die die: dieList){ | ||
outputFile.println(die.name() + ":" + die.value()); | ||
} | ||
// Close file and empty ArrayList for line of dice | ||
outputFile.println("----------END OF SET------------"); | ||
rolledDice.close(); | ||
dieList.removeAll(dieList); | ||
} | ||
catch(IOException e) | ||
{ | ||
System.out.println(e.getMessage()); | ||
} | ||
} // End For that reads each line | ||
} | ||
} |
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,57 @@ | ||
/* | ||
* 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 dnddiceroller; | ||
import java.util.Random; | ||
/** | ||
* Fudged Die class that implements Die interface | ||
* When created the user can give the Die as many sides | ||
* as they want. The method doesn't care and returns -1, 0, or 1. | ||
* @author Tehold | ||
*/ | ||
public class FudgedDie implements Die{ | ||
private int value; | ||
private int sides; | ||
private final String name = "Fudged"; | ||
|
||
/** | ||
* Default Constructor | ||
*/ | ||
public FudgedDie() { | ||
this.value = 0; | ||
this.sides = 3; | ||
} | ||
/** | ||
* Constructor with Parameter for sides to make the user feel good | ||
* @param sides | ||
*/ | ||
public FudgedDie(int sides) { | ||
this.sides = sides; | ||
this.value = 0; | ||
} | ||
/** | ||
* Returns the value of a FudgeDie | ||
* @return Integer Value of Die | ||
*/ | ||
@Override | ||
public int value() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns name of Die | ||
* @return String Fudged | ||
*/ | ||
@Override | ||
public String name() { | ||
return this.name; | ||
} | ||
/** | ||
* Roll Method to determine if the FudgedDie is -1, 0, or 1. | ||
*/ | ||
@Override | ||
public void roll() { | ||
this.value = (new Random()).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,70 @@ | ||
/* | ||
* 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 dnddiceroller; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
*Loaded Die that favors a specified number when rolling. | ||
* @author Tehold | ||
*/ | ||
public class LoadedDie implements Die { | ||
private int value; | ||
private int sides; | ||
private int loadedValue; | ||
private final String name = "Loaded"; | ||
|
||
/** | ||
* Default Constructor for LoadedDie | ||
*/ | ||
public LoadedDie(){ | ||
this.sides = 6; | ||
this.value = 1; | ||
this.loadedValue = 6; | ||
} | ||
/** | ||
* Constructor with parameters for number of sides, and desired value | ||
* @param sides | ||
* @param loadedValue | ||
*/ | ||
public LoadedDie(int sides, int loadedValue) { | ||
this.sides = sides; | ||
this.loadedValue = loadedValue; | ||
this.value = 1; | ||
} | ||
|
||
/** | ||
* Returns the value of a LoadedDie | ||
* @return integer Value of LoadedDie | ||
*/ | ||
@Override | ||
public int value(){ | ||
return this.value; | ||
} | ||
/** | ||
* Returns name of LoadedDie | ||
* @return String Loaded | ||
*/ | ||
@Override | ||
public String name() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* Method to roll the die and assign random value | ||
* If value is not equal to loaded value roll twice more or until | ||
* it is equal to loaded value | ||
*/ | ||
@Override | ||
public void roll() { | ||
this.value = (new Random()).nextInt(this.sides) +1; | ||
for(int i = 0; i < 2; i++) { | ||
if(this.value != this.loadedValue) { | ||
this.value = (new Random()).nextInt(this.sides) +1; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
This is where you would test if a line has valid input