forked from ilikecats/papercats
Add bot stub
This commit is contained in:
parent
c8cd3d474b
commit
858b8f0434
34
game-client-bot.js
Normal file
34
game-client-bot.js
Normal file
@ -0,0 +1,34 @@
|
||||
if (process.argv.length < 3) {
|
||||
console.log("Usage: node game-client-bot.js <socket-url> [<name>]")
|
||||
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) {
|
||||
});
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user