diff --git a/game-client-bot.js b/game-client-bot.js new file mode 100644 index 0000000..e8ef638 --- /dev/null +++ b/game-client-bot.js @@ -0,0 +1,34 @@ +if (process.argv.length < 3) { + console.log("Usage: node game-client-bot.js []") + process.exit(1); +} + +var client = require("./player-client.js"); +var consts = require("./game-consts.js"); +var user; + +var GRID_SIZE = consts.GRID_SIZE; +var CELL_WIDTH = consts.CELL_WIDTH; + +client.allowAnimation = false; + +client.renderer = { + disconnect: function() { + console.log("I died..."); + process.exit(0); + }, + + setUser: function(u) { + user = u; + }, + + update: function(frame) { + if (frame % 6 == 1) + { + //TODO: decide move. + } + } +}; + +client.connectGame(process.argv[2], process.argv[3] || '[BOT]', function(success, msg) { +}); \ No newline at end of file diff --git a/game-client.js b/game-client.js index c1c8e8b..73c6280 100644 --- a/game-client.js +++ b/game-client.js @@ -16,17 +16,15 @@ client.renderer = require("./game-renderer.js"); // window.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { // window.setTimeout( callback, 1000 / 60 ); // }; -var global; -if (!global) - global = window; -if ( !global.requestAnimationFrame ) { - global.requestAnimationFrame = ( function() { - return global.webkitRequestAnimationFrame || - global.mozRequestAnimationFrame || - global.oRequestAnimationFrame || - global.msRequestAnimationFrame || + +if ( !this.requestAnimationFrame ) { + this.requestAnimationFrame = ( function() { + return this.webkitRequestAnimationFrame || + this.mozRequestAnimationFrame || + this.oRequestAnimationFrame || + this.msRequestAnimationFrame || function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { - global.setTimeout( callback, 1000 / 60 ); + setTimeout( callback, 1000 / 60 ); }; })(); } @@ -35,7 +33,6 @@ function run() { client.connectGame('//' + window.location.hostname + ':8081', $('#name').val(), function(success, msg) { if (success) { - console.info("Connected to game!"); $("#begin").addClass("hidden"); $("#begin").animate({ opacity: 0 @@ -43,7 +40,6 @@ function run() { } else { - console.error("Unable to connect to game: " + msg); var error = $("#error"); error.text(msg); } diff --git a/player-client.js b/player-client.js index 8127aca..35c96ca 100644 --- a/player-client.js +++ b/player-client.js @@ -32,17 +32,15 @@ var grid = new Grid(consts.GRID_SIZE, function(row, col, before, after) { // window.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { // window.setTimeout( callback, 1000 / 60 ); // }; -var global; -if (!global) - global = window; -if ( !global.requestAnimationFrame ) { - global.requestAnimationFrame = ( function() { - return global.webkitRequestAnimationFrame || - global.mozRequestAnimationFrame || - global.oRequestAnimationFrame || - global.msRequestAnimationFrame || + +if ( !this.requestAnimationFrame ) { + this.requestAnimationFrame = ( function() { + return this.webkitRequestAnimationFrame || + this.mozRequestAnimationFrame || + this.oRequestAnimationFrame || + this.msRequestAnimationFrame || function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) { - global.setTimeout( callback, 1000 / 60 ); + setTimeout( callback, 1000 / 60 ); }; })(); } @@ -129,6 +127,7 @@ function connectGame(url, name, callback) { invokeRenderer('disconnect', []); }); + console.log("HELLO"); socket.emit('hello', { name: name, type: 0, //Free-for-all @@ -327,7 +326,7 @@ function update() { invokeRenderer('removePlayer', [val]); }); - invokeRenderer('update', []); + invokeRenderer('update', [frame]); } //Export stuff