Skip to content

Commit

Permalink
Merge pull request #86 from mkhattat/gui/feat/startupScreen
Browse files Browse the repository at this point in the history
Gui/feat/startup screen
  • Loading branch information
avanderlinden authored Nov 3, 2017
2 parents eb84617 + b7ea925 commit 28bd700
Show file tree
Hide file tree
Showing 36 changed files with 764 additions and 855 deletions.
86 changes: 1 addition & 85 deletions src/main/java/nl/tudelft/item/EasyItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
*/
public class EasyItemFactory implements ItemFactory {

/**
* The lower bound used for randomly generating items.
*/
private int lowerBound;

/**
* The upper bound used for randomly generating items.
*/
private int upperBound;

/**
* Random used to generate random items by generating random ints.
* These ints will be between the lower bound (inclusive) and the upper bound (exclusive).
Expand Down Expand Up @@ -55,16 +45,6 @@ public EasyItemFactory() {
itemNames.add("mask");
itemNames.add("mouth");

resetRandom();
}

/**
* Resets the upper and lower bound to the default values.
* Also re-initializes the intGen.
*/
public void resetRandom() {
lowerBound = 0;
upperBound = itemHashMap.size();
intGen = new Random();
}

Expand All @@ -76,77 +56,13 @@ public int getItemCount() {
return itemHashMap.size();
}

/**
* Retrieves the lower bound used for generating random items.
* @return The lower bound used for generating random items.
*/
public int getLowerBound() {
return lowerBound;
}

/**
* Sets the lower bound used for generating random items.
* @param newLowerBound The new lower bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new lower bound is larger than
* or equal to the current upper bound, or if the new lower bound is negative.
*/
public void setLowerBound(int newLowerBound) throws IllegalArgumentException {
if (newLowerBound >= upperBound) {
throw new IllegalArgumentException(
"The lower bound may not be larger than or equal to the upper bound."
+ "\nCurrent upper bound: " + upperBound
+ ", new lower bound: " + newLowerBound + ".");
}
if (newLowerBound < 0) {
throw new IllegalArgumentException("The lower bound may not be negative."
+ "\nThe new lower bound: " + newLowerBound + ".");
}
lowerBound = newLowerBound;
}

/**
* Retrieves the upper bound used for generating random items.
* @return The upper bound used for generating random items.
*/
public int getUpperBound() {
return upperBound;
}

/**
* Sets the upper bound used for generating random items.
* @param newUpperBound The new upper bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new upper bound is smaller than
* or equal to the current lower bound, or if the new upper bound is negative.
*/
public void setUpperBound(int newUpperBound) throws IllegalArgumentException {
if (newUpperBound < 0) {
throw new IllegalArgumentException("The upper bound may not be negative."
+ "\nThe new upper bound: " + newUpperBound + ".");
}
if (newUpperBound <= lowerBound) {
throw new IllegalArgumentException(
"The upper bound may not be smaller than or equal to the lower bound."
+ "\nNew upper bound: " + newUpperBound
+ ", current lower bound: " + lowerBound + ".");
}
upperBound = newUpperBound;
}

/**
* Retrieves the random int generator used for generating random items.
* @return The random int generator used for generating random items.
*/
public Random getIntGen() {
return intGen;
}

/**
* Randomly creates one of the following items:
* Axe, Bone, Eye, Leaf, Mask or Mouth.
* @return A random item.
*/
public Item createRandomItem() {
int r = (intGen.nextInt(upperBound - lowerBound) + lowerBound) % itemHashMap.size();
int r = intGen.nextInt(getItemCount());
return itemHashMap.get(itemNames.get(r));
}

Expand Down
42 changes: 0 additions & 42 deletions src/main/java/nl/tudelft/item/ItemFactory.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,16 @@
package nl.tudelft.item;

import java.util.Random;

/**
* Interface for ItemFactories.
*/
public interface ItemFactory {

/**
* Resets the upper and lower bound to the default values.
* Also re-initializes the intGen.
*/
void resetRandom();

/**
* Retrieves the amount of different items.
* @return The amount of different items.
*/
int getItemCount();

/**
* Retrieves the lower bound used for generating random items.
* @return The lower bound used for generating random items.
*/
int getLowerBound();

/**
* Sets the lower bound used for generating random items.
* @param newLowerBound The new lower bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new lower bound is larger than
* or equal to the current upper bound, or if the new lower bound is negative.
*/
void setLowerBound(int newLowerBound) throws IllegalArgumentException;

/**
* Retrieves the upper bound used for generating random items.
* @return The upper bound used for generating random items.
*/
int getUpperBound();

/**
* Sets the upper bound used for generating random items.
* @param newUpperBound The new upper bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new upper bound is smaller than
* or equal to the current lower bound, or if the new upper bound is negative.
*/
void setUpperBound(int newUpperBound) throws IllegalArgumentException;

/**
* Retrieves the random int generator used for generating random items.
* @return The random int generator used for generating random items.
*/
Random getIntGen();

/**
* Randomly creates an item.
* @return A random item.
Expand Down
86 changes: 1 addition & 85 deletions src/main/java/nl/tudelft/item/StandardItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
*/
public class StandardItemFactory implements ItemFactory {

/**
* The lower bound used for randomly generating items.
*/
private int lowerBound;

/**
* The upper bound used for randomly generating items.
*/
private int upperBound;

/**
* Random used to generate random items by generating random ints.
* These ints will be between the lower bound (inclusive) and the upper bound (exclusive).
Expand Down Expand Up @@ -57,16 +47,6 @@ public StandardItemFactory() {
itemNames.add("mouth");
itemNames.add("sun");

resetRandom();
}

/**
* Resets the upper and lower bound to the default values.
* Also re-initializes the intGen.
*/
public void resetRandom() {
lowerBound = 0;
upperBound = itemHashMap.size();
intGen = new Random();
}

Expand All @@ -78,77 +58,13 @@ public int getItemCount() {
return itemHashMap.size();
}

/**
* Retrieves the lower bound used for generating random items.
* @return The lower bound used for generating random items.
*/
public int getLowerBound() {
return lowerBound;
}

/**
* Sets the lower bound used for generating random items.
* @param newLowerBound The new lower bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new lower bound is larger than
* or equal to the current upper bound, or if the new lower bound is negative.
*/
public void setLowerBound(int newLowerBound) throws IllegalArgumentException {
if (newLowerBound >= upperBound) {
throw new IllegalArgumentException(
"The lower bound may not be larger than or equal to the upper bound."
+ "\nCurrent upper bound: " + upperBound
+ ", new lower bound: " + newLowerBound + ".");
}
if (newLowerBound < 0) {
throw new IllegalArgumentException("The lower bound may not be negative."
+ "\nThe new lower bound: " + newLowerBound + ".");
}
lowerBound = newLowerBound;
}

/**
* Retrieves the upper bound used for generating random items.
* @return The upper bound used for generating random items.
*/
public int getUpperBound() {
return upperBound;
}

/**
* Sets the upper bound used for generating random items.
* @param newUpperBound The new upper bound used for generating random items.
* @throws IllegalArgumentException Is thrown if the new upper bound is smaller than
* or equal to the current lower bound, or if the new upper bound is negative.
*/
public void setUpperBound(int newUpperBound) throws IllegalArgumentException {
if (newUpperBound < 0) {
throw new IllegalArgumentException("The upper bound may not be negative."
+ "\nThe new upper bound: " + newUpperBound + ".");
}
if (newUpperBound <= lowerBound) {
throw new IllegalArgumentException(
"The upper bound may not be smaller than or equal to the lower bound."
+ "\nNew upper bound: " + newUpperBound
+ ", current lower bound: " + lowerBound + ".");
}
upperBound = newUpperBound;
}

/**
* Retrieves the random int generator used for generating random items.
* @return The random int generator used for generating random items.
*/
public Random getIntGen() {
return intGen;
}

/**
* Randomly creates one of the following items:
* Axe, Bone, Eye, Leaf, Mask, Mouth or Sun.
* @return A random item.
*/
public Item createRandomItem() {
int r = (intGen.nextInt(upperBound - lowerBound) + lowerBound) % itemHashMap.size();
int r = intGen.nextInt(getItemCount());
return itemHashMap.get(itemNames.get(r));
}

Expand Down
Loading

0 comments on commit 28bd700

Please sign in to comment.