mirror of
https://github.com/fooflington/wordsearch.git
synced 2025-01-22 17:29:55 +00:00
swap "simple" logic to Modes logic
This commit is contained in:
parent
21c558950c
commit
f869de337f
@ -61,8 +61,8 @@ public class GridFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Direction[] directions = new Direction[] { Direction.N, Direction.NE, Direction.E, Direction.SE, Direction.S, Direction.SW, Direction.W, Direction.NW };
|
private static Direction[] directions = new Direction[] { Direction.N, Direction.NE, Direction.E, Direction.SE, Direction.S, Direction.SW, Direction.W, Direction.NW };
|
||||||
private static Direction getDirection(boolean simple) {
|
private static Direction getDirection(Modes mode) {
|
||||||
if(simple) {
|
if(mode == Modes.SIMPLE || mode == Modes.CROSSWORD) {
|
||||||
return rnd.nextBoolean() ? Direction.E : Direction.S;
|
return rnd.nextBoolean() ? Direction.E : Direction.S;
|
||||||
} else {
|
} else {
|
||||||
return directions[rnd.nextInt(directions.length-1)];
|
return directions[rnd.nextInt(directions.length-1)];
|
||||||
@ -161,14 +161,12 @@ public class GridFactory {
|
|||||||
public static char[][] makeGrid(List<String> words, int height, int width, Modes mode) {
|
public static char[][] makeGrid(List<String> words, int height, int width, Modes mode) {
|
||||||
char[][] grid = new char[height][width];
|
char[][] grid = new char[height][width];
|
||||||
|
|
||||||
boolean simple = (mode == Modes.SIMPLE || mode == Modes.CROSSWORD);
|
|
||||||
|
|
||||||
// Place words at random?
|
// Place words at random?
|
||||||
for (String word : words) {
|
for (String word : words) {
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
try {
|
||||||
grid = placeWord(word, grid, simple);
|
grid = placeWord(word, grid, mode);
|
||||||
break;
|
break;
|
||||||
} catch (CouldNotPlaceWordException e) {
|
} catch (CouldNotPlaceWordException e) {
|
||||||
if(tries > MAX_TRIES) {
|
if(tries > MAX_TRIES) {
|
||||||
@ -196,8 +194,8 @@ public class GridFactory {
|
|||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char[][] placeWord(String word, char[][] grid, boolean simple) throws CouldNotPlaceWordException {
|
private static char[][] placeWord(String word, char[][] grid, Modes mode) throws CouldNotPlaceWordException {
|
||||||
Direction direction = getDirection(simple);
|
Direction direction = getDirection(mode);
|
||||||
Bounds b = getBounds(grid.length, grid[0].length, direction, word.length());
|
Bounds b = getBounds(grid.length, grid[0].length, direction, word.length());
|
||||||
// System.out.println("[" + word + "] bounds: " + b);
|
// System.out.println("[" + word + "] bounds: " + b);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user