mirror of
https://github.com/fooflington/wordsearch.git
synced 2025-01-22 17:29:55 +00:00
Start allowing more than just Normal and Simple mode... crossword mode won't fill in the random letters.
This commit is contained in:
parent
3c18a2c831
commit
cc2c7eee29
@ -155,12 +155,14 @@ public class GridFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static char[][] makeGrid(List<String> words, int height, int width) {
|
public static char[][] makeGrid(List<String> words, int height, int width) {
|
||||||
return makeGrid(words, height, width, false);
|
return makeGrid(words, height, width, Modes.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char[][] makeGrid(List<String> words, int height, int width, boolean simple) {
|
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];
|
||||||
|
|
||||||
|
bool 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;
|
||||||
@ -180,12 +182,14 @@ public class GridFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill rest of grid
|
if(mode != Modes.CROSSWORD) {
|
||||||
for (int y=0; y<height; y++) {
|
// Fill rest of grid
|
||||||
for (int x=0; x<width; x++) {
|
for (int y=0; y<height; y++) {
|
||||||
if (grid[y][x] == Character.UNASSIGNED)
|
for (int x=0; x<width; x++) {
|
||||||
// grid[y][x] = '_';
|
if (grid[y][x] == Character.UNASSIGNED)
|
||||||
grid[y][x] = getRandomChar();
|
// grid[y][x] = '_';
|
||||||
|
grid[y][x] = getRandomChar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,11 @@
|
|||||||
|
|
||||||
int height = Integer.parseInt(request.getParameter("height"));
|
int height = Integer.parseInt(request.getParameter("height"));
|
||||||
int width = Integer.parseInt(request.getParameter("width"));
|
int width = Integer.parseInt(request.getParameter("width"));
|
||||||
boolean simple = request.getParameter("simple") != null;
|
Modes mode = Modes.NORMAL;
|
||||||
|
if(request.getParameter("mode") != null) {
|
||||||
|
if(request.getParameter("mode") == "SIMPLE") mode = Modes.SIMPLE;
|
||||||
|
if(request.getParameter("mode") == "CROSSWORD") mode = Modes.CROSSWORD;
|
||||||
|
}
|
||||||
String name = StringEscapeUtils.escapeHtml(request.getParameter("name"));
|
String name = StringEscapeUtils.escapeHtml(request.getParameter("name"));
|
||||||
|
|
||||||
if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); }
|
if (request.getParameter("words").length() > 2048) { throw new Exception("Input too large"); }
|
||||||
@ -25,7 +29,7 @@
|
|||||||
}
|
}
|
||||||
Collections.sort(words);
|
Collections.sort(words);
|
||||||
|
|
||||||
char[][] grid = GridFactory.makeGrid(words, height, width, simple);
|
char[][] grid = GridFactory.makeGrid(words, height, width, mode);
|
||||||
|
|
||||||
String csv = "";
|
String csv = "";
|
||||||
%>
|
%>
|
||||||
|
@ -25,7 +25,9 @@ Dining Room
|
|||||||
<br />
|
<br />
|
||||||
<input type="number" name="height" min="3" max="50" value="15" />
|
<input type="number" name="height" min="3" max="50" value="15" />
|
||||||
<input type="number" name="width" min="3" max="50" value="15" />
|
<input type="number" name="width" min="3" max="50" value="15" />
|
||||||
<input type="checkbox" name="simple" value="yes">Simple [<span class="tooltip" title="In simple mode, words are only placed Left-to-Right or Top-to-Bottom">?</span>]</span>
|
<input type="radio" name="mode" value="NORMAL" checked />Normal
|
||||||
|
<input type="radio" name="mode" value="SIMPLE" />Simple[<span class="tooltip" title="In simple mode, words are only placed Left-to-Right or Top-to-Bottom">?</span>]
|
||||||
|
<input type="radio" name="mode" value="CROSSWORD" />Crossword
|
||||||
<input type="submit" value="Build!" />
|
<input type="submit" value="Build!" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user