public class PlayfieldGenerator
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
PlayfieldGenerator.GeneratorProgressListener
Listener interface for classes that want to
informed of playfield generation progress.
|
Modifier and Type | Field and Description |
---|---|
private static int |
AREA_DIV_NUM
The area of the base triangle is divided this to set the
minimum required area for an object
|
private float |
coverage
Desired playfield coverage.
|
private int |
coverageNum
Coverage value in range 0-255.
|
private static double |
DIAGONAL_LENGTH_RATIO
Ratio between the length of both diagonals in an object (recommended between 1.0 and 1.8).
|
private PlayfieldGenerator.GeneratorProgressListener |
listener
Listener to notify of generation progress.
|
private java.util.Random |
random
Local random instance to use the generate the playfield.
|
private int |
rangeMax
Maximum object size.
|
private int |
rangeMin
Minimum object size.
|
private float |
scale
Object scaling factor.
|
private int |
scaleNum
Scaling value in range 0-255.
|
private long |
seed
The random seed for this playfield generator.
|
Constructor and Description |
---|
PlayfieldGenerator()
Constructs a new playfield generator with a random seed,
range of 0-100, coverage of 0.2745 and scale of 0.78.
|
PlayfieldGenerator(java.lang.String seed)
Constructs a new playfield generate with the given seed.
|
Modifier and Type | Method and Description |
---|---|
private double |
areaObject(int rMax)
Function to determine the approximate minimum area for an object
|
java.util.List<ConvexObject> |
generatePlayfield()
Generates a new game playfield with convex objects made up of 3 to 4 points.
|
int |
getCoverage()
Gets the coverage number for this generator.
|
int |
getRangeMax()
Gets the minimum size range for this generator.
|
int |
getRangeMin()
Gets the maximum size range for this generator.
|
int |
getScaling()
Gets the scaling number for this generator.
|
java.lang.String |
getSeed()
Gets the seed that describes this random generator.
|
private static boolean |
hasSeedMarker(long high)
Checks if the given high order bits of a seed
represent a valid game seed.
|
private void |
init(long seed,
int rangeMin,
int rangeMax,
int coverageNum,
int scaleNum)
Initialises the internal generator state.
|
static boolean |
isValidSeed(java.lang.String seed)
Tests if the given seed is a valid game seed.
|
void |
setCoverage(int coverage)
Sets the minimum total area of the whole playfield that should be
covered by convex objects before scaling.
|
void |
setProgressListener(PlayfieldGenerator.GeneratorProgressListener listener)
Sets the listener to notify of playfield generation progress.
|
void |
setRange(int min,
int max)
Sets the size range of generated objects.
|
void |
setScaling(int scaling)
Sets the factor by with which to scale all objects after generation.
|
void |
setSeed(java.lang.String seed)
Sets the seed of this generator to the given seed.
|
private static final int AREA_DIV_NUM
private static final double DIAGONAL_LENGTH_RATIO
private java.util.Random random
private long seed
private int rangeMin
private int rangeMax
private int coverageNum
coverage
private int scaleNum
scale
private float coverage
private float scale
private PlayfieldGenerator.GeneratorProgressListener listener
public PlayfieldGenerator()
public PlayfieldGenerator(java.lang.String seed) throws java.lang.IllegalArgumentException
seed
- The seed to use.java.lang.IllegalArgumentException
- When the given seed is invalidpublic void setProgressListener(PlayfieldGenerator.GeneratorProgressListener listener)
listener
- The listener to register.PlayfieldGenerator.GeneratorProgressListener
private void init(long seed, int rangeMin, int rangeMax, int coverageNum, int scaleNum)
seed
- Random number generator seed.rangeMin
- Minimum object size.rangeMax
- Maximum object size.coverageNum
- Playfield coverage.scaleNum
- Object scaling.public void setSeed(java.lang.String seed) throws java.lang.IllegalArgumentException
seed
- The new seed.java.lang.IllegalArgumentException
- When the seed is invalid.isValidSeed(String)
public int getRangeMin()
setRange(int, int)
public int getRangeMax()
setRange(int, int)
public int getCoverage()
setCoverage(int)
public int getScaling()
setScaling(int)
public java.lang.String getSeed()
public void setRange(int min, int max) throws java.lang.IllegalArgumentException
min
- The minimum size range for convex objects (at least 0).max
- The maximum size range for convex objects. Small values for
this parameter may resulting in generating the playfield taking longer,
values larger than 20 are recommended (at most 255).java.lang.IllegalArgumentException
- When the given range is invalid.public void setCoverage(int coverage) throws java.lang.IllegalArgumentException
coverage / 255
is 0.5 or less (so at most 127).coverage
- The new coverage value.java.lang.IllegalArgumentException
- When the given value is out of range (0 - 255).public void setScaling(int scaling) throws java.lang.IllegalArgumentException
scaling
- The scaling factor, computed as scaling / 255
.java.lang.IllegalArgumentException
- When the given value is out of range (0 - 255).private double areaObject(int rMax)
rMax
- The maximum range for an object.public java.util.List<ConvexObject> generatePlayfield()
public static boolean isValidSeed(java.lang.String seed)
seed
- The seed to test.private static boolean hasSeedMarker(long high)
high
- The high order seed bits.