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

help, lost! #4

Open
wants to merge 8 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
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\\Zachary\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
16 changes: 16 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/Die.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceReaderTest.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/DnDDiceRoller.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/assignment/pkg9/DiceFileReader.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/Load.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/DiceTower.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/Fudge.java</file>
<file>file:/C:/Users/Zachary/Documents/GitHub/CPT-163-27-F2015-Assignment-9-Files-Strings/src/dnddiceroller/NumberedDie.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=dnddiceroller.DnDDiceRoller
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
17 changes: 15 additions & 2 deletions src/assignment/pkg9/DiceFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class DiceFileReader {
public DiceFileReader(String filePath) {
this.filePath = filePath;

File inputFile = new File(filePath);
File DiceFile = new File(filePath);

try {
this.input = new Scanner(inputFile);
this.input = new Scanner(DiceFile);
} catch (FileNotFoundException ex) {
Logger.getLogger(DiceFileReader.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -46,5 +46,18 @@ public List<String> getLines(){
public void read(){
this.lines = new ArrayList();
// Put you read logic and populate lines
for(int i=0; i<1; i++){
this.input.nextLine();

while (this.input.hasNext()){
String currentLine= this.input.nextLine();
if(!currentLine.contains("####")){
this.lines.add(currentLine);
}

}
this.input.close();
}

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

import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;

/**
* 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;
private int trayValue;
private List<Die> dice;

public DiceTower(int trayValue, List<Die> dice) {
this.trayValue = trayValue;
this.dice = dice;
}





//for loop in this
public void dropDice(){
for(int i=0; i<this.dice.size();i++){
this.dice.get(i).rollDice();
}

}

//consturctor for variables out of array list function
public DiceTower(List dice) {
this.dice=dice;

}


//this will retunr the value of trayValue
public int getTrayValue(){
return trayValue;
}


}


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

import java.io.*;
import java.util.Scanner;

/**
* 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 interface Die {

public int rollDice(); //variable for rolling
public int getValue(); //to get value from
}
93 changes: 93 additions & 0 deletions src/dnddiceroller/DnDDiceRoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dnddiceroller;

import assignment.pkg9.DiceFileReader;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
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) throws FileNotFoundException {
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);
}
DiceFileReader diceReader = diceReader = new DiceFileReader("./dice.txt");
}
Scanner scanner = null;
ArrayList<String> list = new ArrayList<String>();
File temp = new File ("dice.txt");
Scanner file = new Scanner (temp);
Copy link
Member

Choose a reason for hiding this comment

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

You assigned this scanner to file instead of scanner so it can't read any lines

String s = scanner.nextLine();

String lineToRemove="#";
String currentLine;


while(file.hasNext()){
s = scanner.nextLine();
String[] tempList=s.split(" ");
String title = tempList[0];
String type = tempList[1].substring(1);
list.add(title);
}
while(file.hasNext()){
s=scanner.nextLine();
String[] tempList=s.split(":");
String title=tempList[0];
String type=tempList[1].substring(1);
list.add(title);

}

System.out.println(s);





}

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


}

public static int test_diceTowerWithTwoD6(){
List<NumberedDie> dice = new ArrayList();//declaring an array list
dice.add(new NumberedDie(6));
dice.add(new NumberedDie(6));
DiceTower tower = new DiceTower(dice);//new dicetower value to dice
tower.dropDice();//drop dice method access class
int trayValue = tower.getTrayValue();//getting the valye of tray
if(trayValue >= 2 && trayValue <= 12){
return -1; // means the die value is outside the bounds of 2 d6
}else{
return trayValue; //return the value of trayvalue if if statement is false. else
}
}

}
42 changes: 42 additions & 0 deletions src/dnddiceroller/Fudge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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;
import java.io.*;
import java.util.Scanner;
/**
*
* @author Zachary
*/
public class Fudge implements Die {
private int sideOfDie;
private int valueOfDie;

public int getvaleOfDie(){
return valueOfDie;

}

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

public int roll(){
Random rand1=new Random();
return this.valueOfDie=rand1.nextInt(this.sideOfDie)-1;
}

@Override
public int rollDice() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public int getValue() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
47 changes: 47 additions & 0 deletions src/dnddiceroller/Load.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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;
import java.io.*;
import java.util.Scanner;
/**
*
* @author Zachary
*/
public class Load implements Die{
private int sideOfDie;
private int valueOfDie;


public int getvaleOfDie(){
return valueOfDie;

}

public Load (int sideOfDie){
this.sideOfDie=sideOfDie;
}

public int roll(){
Random rand1=new Random();
this.valueOfDie=rand1.nextInt(this.sideOfDie)+1;
while(this.valueOfDie<this.sideOfDie){
this.valueOfDie=rand1.nextInt(this.sideOfDie)+1;///loop to repated
}
return this.sideOfDie;
}

@Override
public int rollDice() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public int getValue() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
42 changes: 42 additions & 0 deletions src/dnddiceroller/NumberedDie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.io.*;
import java.util.Scanner;
import java.util.Random;

/**
*
* @author Zachary
*/
public class NumberedDie implements Die{
private int valueOfDie;
private int sideOfDie;


//con to get the # of sides oof the value
public NumberedDie(int sideOfDie){
this.sideOfDie=sideOfDie;

}
//access
public int getvalueOfDie(){
return valueOfDie;
}


@Override
public int rollDice() {
Random rand1=new Random();
return this.valueOfDie=rand1.nextInt(this.sideOfDie)+1;
}

@Override
public int getValue() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}