Skip to content

Instantly share code, notes, and snippets.

@chee
Forked from wraithan/fightcodegame.com.js
Last active December 15, 2015 13:28
Show Gist options
  • Save chee/5267177 to your computer and use it in GitHub Desktop.
Save chee/5267177 to your computer and use it in GitHub Desktop.
var replayURL = 'http://fightcodegame.com/robots/replay/';
var ai = 'duck';
function load ( event ) {
event.preventDefault();
var playerNumber = $( '#playerNumber' ).val();
var replayID = $( '#replayID' ).val();
$.get( replayURL + replayID ).done(function ( data ) {
var player = $( data ).filter( '[id*="-code"]' ).eq( playerNumber ).text();
$( '#' + ai + '-code' ).text( player );
// refresh the ai
$( '#enemy' ).val( ai ).change();
});
}
if ( $( '.editor' ).length ) {
var form = $( '<form class="form"><input id="replayID"><select id="playerNumber"><option value="0" name="1">1</option><option value="1" name="2">2</option></select><button class="load">Load Bot</button></form>' );
$( '.buttons-bar' ).append( form );
form.on( 'click', '.load', load );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment