now displaying names of available robots for user, on startup (changes to js and html)

This commit is contained in:
Richard Harrington 2013-08-24 08:55:47 -04:00
parent 4fe79afffd
commit 6845fa51d8
2 changed files with 26 additions and 13 deletions

View File

@ -15,6 +15,7 @@
<p>Type the names of up to five programs to load into the battle robots.</p>
<p>You may choose more than one of each.</p>
<p>Then press return.</p>
<p>(available robots: <span id="programNames"></span>)</p>
<input id="programsInput" type="text" autofocus></input>
<canvas id="canvas" width="600" height="600"></canvas>
</div>

View File

@ -255,19 +255,31 @@
});
}
// Text and keyboard event listeners for sending program names to
// server
function init() {
// Text and keyboard event listeners for sending program names to
// server
$('#programsInput').bind('keydown', function(event) {
if (event.which === 13) {
event.stopPropagation();
event.preventDefault();
if (worlds) {
worlds.finish();
$('#programsInput').bind('keydown', function(event) {
if (event.which === 13) {
event.stopPropagation();
event.preventDefault();
if (worlds) {
worlds.finish();
}
var programs = this.value;
worlds = new Worlds(programs, BUFFER_LENGTH, startGame);
$(this).blur();
}
var programs = this.value;
worlds = new Worlds(programs, BUFFER_LENGTH, startGame);
$(this).blur();
}
});
});
// Fetch list of robots for user
$.getJSON('program-names', function(data) {
$('#programNames').text(data.names.join(", "));
$('body').css({display: 'block'});
});
}
// Fire it up.
$(init);
})();