Start allowing more than just Normal and Simple mode... crossword mode won't fill in the random letters.

This commit is contained in:
Matthew Slowe 2017-10-08 22:02:56 +01:00
parent 3c18a2c831
commit cc2c7eee29
No known key found for this signature in database
GPG Key ID: DE311E1AC27AC583
3 changed files with 21 additions and 11 deletions

View File

@ -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,6 +182,7 @@ public class GridFactory {
} }
} }
if(mode != Modes.CROSSWORD) {
// Fill rest of grid // Fill rest of grid
for (int y=0; y<height; y++) { for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) { for (int x=0; x<width; x++) {
@ -188,6 +191,7 @@ public class GridFactory {
grid[y][x] = getRandomChar(); grid[y][x] = getRandomChar();
} }
} }
}
return grid; return grid;
} }

View File

@ -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 = "";
%> %>

View File

@ -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>