Skip to content

Instantly share code, notes, and snippets.

@DerMitch
Created October 5, 2013 09:00
Show Gist options
  • Save DerMitch/6838552 to your computer and use it in GitHub Desktop.
Save DerMitch/6838552 to your computer and use it in GitHub Desktop.
Gather and hut-building "bot" for A dark room (http://adarkroom.doublespeakgames.com/)
if ( window.AG ) {
window.AG.reset();
delete window.AG;
}
var AutoGame = function() {
this.gather_btn = $('#gatherButton');
this.traps_btn = $('#trapsButton');
this.buildtrap_btn = $('#build_trap');
this.buildhut_btn = $('#build_hut');
this.gather_timeout = null;
this.build_timeout = null;
};
AutoGame.prototype.start = function() {
var self = this;
this.gather_timeout = window.setInterval(function() {
/* Collect wood */
if ( !self.gather_btn.hasClass('disabled') ) self.gather_btn.click();
/* Collect traps */
if ( !self.traps_btn.hasClass('disabled') ) self.traps_btn.click();
}, 2000);
this.build_timeout = window.setInterval(function() {
/* Build traps if possible */
if ( !self.buildtrap_btn.hasClass('disabled') )
self.buildtrap_btn.click();
/* Build hut if possible */
if ( !self.buildhut_btn.hasClass('disabled') )
self.buildhut_btn.click();
}, 15000);
};
AutoGame.prototype.reset = function() {
if ( this.gather_timeout )
window.clearInterval(this.gather_timeout);
if ( this.build_timeout )
window.clearInterval(this.build_timeout);
};
window.AG = new AutoGame();
AG.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment