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

New changes Wip #9

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
10 changes: 10 additions & 0 deletions Dice Output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Line 1: 20:loaded:6, 10:numbered, 6:fudge, 10:fudge, 20:fudge
Line 1 total: 1
Line 2: 4:loaded:1, 10:numbered, 6:fudge, 100:numbered, 5:numbered
Line 2 total: 20
Line 3: 8:fudge, 8:numbered, 8:loaded:4
Line 3 total: 3
Line 4: 10:numbered, 10:numbered, 10:numbered, 10:numbered
Line 4 total: 17
Line 5: 6:fudge, 6:loaded:2, 6:loaded:4, 6:loaded:6
Line 5 total: 10
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\\Inspiron\\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/Inspiron/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/dnddiceroller/DiceFileReader.java</file>
<file>file:/C:/Users/Inspiron/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/dnddiceroller/DnDDiceRoller.java</file>
<file>file:/C:/Users/Inspiron/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/dnddiceroller/LoadedDice.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.dnddiceroller.DnDDiceRoller
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg9;
package assignment.dnddiceroller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
Expand Down Expand Up @@ -39,12 +41,39 @@ public DiceFileReader(String filePath) {
}
}

public List<String> getLines(){


public DiceFileReader(String filePath, List<String> lines) {
this.filePath = filePath;
this.lines = lines;
}
public List<String> getLines(){
return this.lines;
}
}

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

try {
while(input.hasNextLine()) {
String temp = input.nextLine();
if(temp.charAt(0) != '#'){
lines.add(temp);
}
}
}
catch (Exception e)
{
System.out.println(e.getLocalizedMessage());
}
}


}
}







Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg9;
package assignment.dnddiceroller;

import assignment.dnddiceroller.DiceFileReader;

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

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;

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

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

public void dropDice() {
for (int i = 0; i < PANEL_COUNT; i++) {
for (int j = 0; j < dice.size(); j++) {
Die temp = dice.get(j);
temp.roll();
}
}
}

public int trayValue() {
int totalValue = 0;
for (int i = 0; i < dice.size(); i++) {
Die temp = dice.get(i);
totalValue = totalValue + temp.value();

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

/**
*
* @author Inspiron
*/
public abstract interface Die {

void roll();
int value();


}
100 changes: 100 additions & 0 deletions src/assignment/dnddiceroller/DnDDiceRoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package assignment.dnddiceroller;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
*
* @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) {
String File = "dice.txt";
List<String> DiceList;
DiceFileReader DiceFile = new DiceFileReader(File);
Die temp;
try {
File diceOutput = new File("Dice Output.txt");
PrintWriter output = new PrintWriter(diceOutput);


DiceFile.read();
DiceList = DiceFile.getLines();

for(int i = 0; i < DiceList.size(); i++) {

List<Die> dice = new ArrayList<Die>();

output.print("Line " + (i+1) + ": ");
for (StringTokenizer stringTokenizer = new StringTokenizer(DiceList.get(i)
," "); stringTokenizer.hasMoreTokens();) {
int die;
String type;
int loaded;

String token = stringTokenizer.nextToken();

output.print(token);

StringTokenizer dieTokens = new StringTokenizer(token,":");

die = Integer.parseInt(dieTokens.nextToken());
type = dieTokens.nextToken();

if (type.equals("loaded"))
{
loaded = Integer.parseInt(dieTokens.nextToken());
temp = new LoadedDice(die,loaded);
}
else if (type.equals("fudge"))
{
temp = new FudgeDice(die);
}
else if (type.equals("numbered"))
{
temp = new NumberedDie(die);
}
else
{
throw new Exception("Invalid die type found on line " + (i+1));
}

dice.add(temp);

if(stringTokenizer.hasMoreElements())
{
output.print(", ");
}
else
output.println();

}
//Create dice tower using dice
//roll dice in dice tower
//output results
DiceTower tower = new DiceTower(dice);
tower.dropDice();
output.println("Line " + (i+1) + " total: " + tower.trayValue());


}

output.close();

}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
33 changes: 33 additions & 0 deletions src/assignment/dnddiceroller/FudgeDice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.dnddiceroller;

import java.util.Random;

/**
*
* @author Inspiron
*/
public class FudgeDice implements Die{
private int die;
private int value;
private Random FudgeRand = new Random();
public FudgeDice(int die){
this.die = die;
}


@Override
public void roll() {
this.value = FudgeRand.nextInt(3)-1;
}

@Override
public int value() {
return this.value;
}

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

import java.util.Random;

/**
*
* @author Inspiron
*/
public class LoadedDice implements Die{
private final int WEIGHT = 2;
private int die;
private int value;
private int loadedValue;
private Random randValue = new Random();
public LoadedDice(int die){
this.die = die;
this.loadedValue = die;
}

public LoadedDice(int die, int loadedValue){
this.die = die;
this.loadedValue = loadedValue;
}

@Override
public void roll() {
int tempValue = 0;
for (int i = 0; i < WEIGHT && this.value != loadedValue; i++) {
tempValue = randValue.nextInt(die)+1;
if (tempValue == loadedValue){
this.value = tempValue;
}

}

if (this.value != loadedValue){
this.value = tempValue;
}



}

@Override
public int value() {
return this.value;
}

}
32 changes: 32 additions & 0 deletions src/assignment/dnddiceroller/NumberedDie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package assignment.dnddiceroller;

import java.util.Random;

/**
* A NumberedDie 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 die;
private int value;
private Random dieSide = new Random();

public NumberedDie(int die) {
this.die = die;

}

@Override
public void roll() {
value = dieSide.nextInt(die) + 1;// dieSide is equal to 0 thri (die -1).
//System.out.println(value);
}

@Override
public int value(){
return this.value;
}
}