Scythe Randomizer
by lukerichison
HTML
<table id="players">
<thead>
<tr>
<th>Who's Playing?</th>
</tr>
</thead>
<tbody>
<tr><td><input type="text" name="player0"></td></tr>
</tbody>
<tfoot>
<tr>
<td>
<input type="button" name="addPlayer" value="+" onclick="addPlayer()">
<input type="button" name="removePlayer" value="-" onclick="removePlayer()">
<input type="button" name="playersDone" value="→" onclick="playersDone()">
</td>
</tr>
</tfoot>
</table>
<input type="checkbox" name="noIndustrialRusviets" id="noIndustrialRusviets" checked><label for="noIndustrialRusviets">Don't allow Rusviet to use the Industrial player mat (strongly recommended by the designer)</label><br/><input type="checkbox" name="invadersFromAfar" id="invadersFromAfar" onchange="updateExpansions()"><label for="invadersFromAfar">Inclued the materials from Invaders From Afar </label>
<table id="exclusions">
<thead>
<tr>
<th>Personal Exclusions</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td>
<input type="button" name="addExclusion" value="+" onclick="addExclusion()">
<input type="button" name="removeExclusion" value="-" onclick="removeExclusion()">
<input type="button" name="exclusionsDone" value="→" onclick="exclusionsDone()">
</td>
</tr>
</tfoot>
</table>
<table id="output">
<thead>
<tr><th>Output</th></tr>
</thead>
<tbody>
</tbody>
</table>
CSS
input[name="playersDone"],
input[name="exclusionsDone"] {
float: right;
}
JavaScript
var playerCount = 1;
var exclusionCount = 0;
var players = [];
var playerTable = document.getElementById("players").getElementsByTagName("tbody")[0];
var exclusionTable = document.getElementById("exclusions").getElementsByTagName("tbody")[0];
var outputTable = document.getElementById("output").getElementsByTagName("tbody")[0];
var baseFactions = ["Polania Republic", "Saxony Empire", "Crimean Khanate", "Nordic Kingdom", "Rusviet Union"];
var invadersFactions = ["Clan Albion", "Togawa Shogunate"];
var factions = [];
Array.prototype.push.apply(factions, baseFactions);
var baseMats = ["1 Industrial", "2 Engineering", "3 Patriotic", "4 Mechanical", "5 Agricultural"]
var invadersMats = ["2a Militant", "3a Innovative"]
var mats = [];
Array.prototype.push.apply(mats, baseMats);
function addPlayer() {
if (playerCount < 7) {
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("name", "player" + playerCount);
var row = playerTable.insertRow(playerCount);
var cell = row.insertCell(0).appendChild(input);
++playerCount;
}
}
function removePlayer() {
if (playerCount > 1) {
--playerCount;
playerTable.deleteRow(playerCount);
}
}
function playersDone() {
var playerInputs = playerTable.getElementsByTagName("input");
for (var i = 0; i < playerInputs.length; i++) {
var playerVal = playerInputs[i].value;
if (playerVal != "") players.push(playerVal);
}
}
function updateExpansions() {
var x = document.getElementById("invadersFromAfar");
if (x.checked == true) {
Array.prototype.push.apply(factions, invadersFactions);
Array.prototype.push.apply(mats, invadersMats);
} else {
factions.splice(baseFactions.length, invadersFactions.length);
mats.splice(baseMats.length, invadersMats.length);
}
}
function addExclusion() {
var selectPlayer = document.createElement("select");
selectPlayer.setAttribute("name", "exclusion" + exclusionCount + "player");
for (var i=-1; i <...