working web

This commit is contained in:
foo 2016-12-18 20:55:35 +00:00
parent 947dd5fcd9
commit 790bdf144e
4 changed files with 114 additions and 20 deletions

31
Makefile Executable file
View File

@ -0,0 +1,31 @@
JAVA = /usr/bin/java
# JAVAFLAGS = -version # -classpath $(LIBS)
JAVAC = /usr/bin/javac
JFLAGS = -g # -classpath $(LIBS)
SRCS = uk/org/mafoo/wordsearch/GridFactory.java \
uk/org/mafoo/wordsearch/Bounds.java \
uk/org/mafoo/wordsearch/CouldNotPlaceWordException.java \
uk/org/mafoo/wordsearch/Direction.java \
uk/org/mafoo/wordsearch/DistributedRandomNumberGenerator.java
OBJS = ${SRCS:.java=.class}
.SUFFIXES: .java .class
all: build wordsearch.jar
run: all
$(JAVA) uk.org.mafoo.wordsearch.GridFactory 10 10
.java.class:
$(JAVAC) $(JFLAGS) $<
build: $(OBJS)
clean:
rm -f $(OBJS) wordsearch.jar wordsearch.war
wordsearch.jar: build
jar cf $@ $(OBJS)
cp wordsearch.jar war/WEB-INF/lib

22
war/about.html Executable file
View File

@ -0,0 +1,22 @@
<html>
<head>
<title>About</title>
</head>
<body>
<h1>Wordsearch Builder: About</h1>
Wordsearch Builder takes a list of words and places them on a grid in any direction allowing the to cross-over where possible then fills in the remaining empty spaces with semi-random letters.
<h2>Basic algorithm</h2>
<ol>
<li>Foreach word
<ol>
<li>Pick a direction at random</li>
<li>Compute possible start points based on word length, direction and grid size</li>
<li>Begin placing word. If an occupied cell is encountered which contains a different character than would go in for this word, then abort and start this word again.</li>
</ol>
</li>
<li>When all words are placed, infill the remaining cells with random characters weighted by <a href="https://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html">standard English letter frequencies</a></li>
</ol>
The abort-and-retry word placement to try 500 times before giving up.
</body>
</html>

View File

@ -7,10 +7,28 @@
border-collapse: collapse; border-collapse: collapse;
padding: 2px 4px; padding: 2px 4px;
} }
#grid {
font-family: monospace; font-size: 16;
}
#wrapper {
width: 80%;
margin: 0 auto;
}
#wordsearch {
float: left;
}
#words {
float: right;
width: 200px;
}
</style> </style>
</head> </head>
<%@ page import="uk.org.mafoo.wordsearch.*" %> <%@ page import="uk.org.mafoo.wordsearch.*" %>
<%@ page import="java.util.*" %> <%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page errorPage="error.jsp" %> <%@ page errorPage="error.jsp" %>
<% <%
@ -24,31 +42,52 @@
for ( String line : request.getParameter("words").split("\r\n")) { for ( String line : request.getParameter("words").split("\r\n")) {
words.add(line.trim()); words.add(line.trim());
} }
Collections.sort(words);
char[][] grid = GridFactory.makeGrid(words, height, width); char[][] grid = GridFactory.makeGrid(words, height, width);
String csv = "";
%> %>
<body> <body>
<h1>Wordsearch builder</h1> <h1>Wordsearch builder</h1>
<h2>Words</h2> <a id='csvdownload'>Download CSV</a>
<script>
<div style="float: right; padding: 15px;"> var csv = '<%= csv %>';
<ul> var csvdownload = document.getElementById('csvdownload');
<% for (String word : words) { %> csvdownload.href='data:text/csv;base64,' + btoa(csv);
<li><%= word.trim() %></li> </script>
<% } %>
</ul>
</div> </div>
<h2>Grid</h2> <div id="wrapper">
<table style="font-family: monospace; font-size: 16;"> <div id="wordsearch">
<% for(char[] row : grid) { %> <h2>Grid</h2>
<tr> <table id="grid">
<% for(char c : row) { %> <% for(char[] row : grid) { %>
<td><%= c %></td> <tr>
<% } %> <% for(char c : row) {
</tr> csv += "" + c + ',';
<% } %> %>
</table> <td><%= c %></td>
<% } %>
</tr>
<%
csv += "\\n";
}
%>
</table>
</div> <!-- end wordsearch -->
<div id="words">
<h2>Words</h2>
<ul>
<% for (String word : words) { %>
<li><%= word.trim() %></li>
<% } %>
</ul>
</div> <!-- end words -->
</div> <!-- end wrapper -->
<br />
<div>
</body> </body>
</html> </html>

View File

@ -2,8 +2,10 @@
<head><title>Wordsearch builder</title></head> <head><title>Wordsearch builder</title></head>
<body> <body>
<h1>Wordsearch builder</h1> <h1>Wordsearch builder</h1>
<a href="about.html">About</a>
<h2>Words</h2> <h2>Words</h2>
<form action="build.jsp"> <form action="build.jsp" method="post">
<textarea name="words" rows="10"> <textarea name="words" rows="10">
Kitchen Kitchen
Lounge Lounge