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.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) {
|
||||||
// window.setTimeout( callback, 1000 / 60 );
|
// window.setTimeout( callback, 1000 / 60 );
|
||||||
// };
|
// };
|
||||||
var global;
|
|
||||||
if (!global)
|
if ( !this.requestAnimationFrame ) {
|
||||||
global = window;
|
this.requestAnimationFrame = ( function() {
|
||||||
if ( !global.requestAnimationFrame ) {
|
return this.webkitRequestAnimationFrame ||
|
||||||
global.requestAnimationFrame = ( function() {
|
this.mozRequestAnimationFrame ||
|
||||||
return global.webkitRequestAnimationFrame ||
|
this.oRequestAnimationFrame ||
|
||||||
global.mozRequestAnimationFrame ||
|
this.msRequestAnimationFrame ||
|
||||||
global.oRequestAnimationFrame ||
|
|
||||||
global.msRequestAnimationFrame ||
|
|
||||||
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) {
|
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) {
|
client.connectGame('//' + window.location.hostname + ':8081', $('#name').val(), function(success, msg) {
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
console.info("Connected to game!");
|
|
||||||
$("#begin").addClass("hidden");
|
$("#begin").addClass("hidden");
|
||||||
$("#begin").animate({
|
$("#begin").animate({
|
||||||
opacity: 0
|
opacity: 0
|
||||||
@ -43,7 +40,6 @@ function run() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.error("Unable to connect to game: " + msg);
|
|
||||||
var error = $("#error");
|
var error = $("#error");
|
||||||
error.text(msg);
|
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.requestAnimationFrame = function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) {
|
||||||
// window.setTimeout( callback, 1000 / 60 );
|
// window.setTimeout( callback, 1000 / 60 );
|
||||||
// };
|
// };
|
||||||
var global;
|
|
||||||
if (!global)
|
if ( !this.requestAnimationFrame ) {
|
||||||
global = window;
|
this.requestAnimationFrame = ( function() {
|
||||||
if ( !global.requestAnimationFrame ) {
|
return this.webkitRequestAnimationFrame ||
|
||||||
global.requestAnimationFrame = ( function() {
|
this.mozRequestAnimationFrame ||
|
||||||
return global.webkitRequestAnimationFrame ||
|
this.oRequestAnimationFrame ||
|
||||||
global.mozRequestAnimationFrame ||
|
this.msRequestAnimationFrame ||
|
||||||
global.oRequestAnimationFrame ||
|
|
||||||
global.msRequestAnimationFrame ||
|
|
||||||
function( /* function FrameRequestCallback */ callback, /* DOMElement Element */ element ) {
|
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', []);
|
invokeRenderer('disconnect', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("HELLO");
|
||||||
socket.emit('hello', {
|
socket.emit('hello', {
|
||||||
name: name,
|
name: name,
|
||||||
type: 0, //Free-for-all
|
type: 0, //Free-for-all
|
||||||
@ -327,7 +326,7 @@ function update() {
|
|||||||
invokeRenderer('removePlayer', [val]);
|
invokeRenderer('removePlayer', [val]);
|
||||||
});
|
});
|
||||||
|
|
||||||
invokeRenderer('update', []);
|
invokeRenderer('update', [frame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Export stuff
|
//Export stuff
|
||||||
|
Loading…
Reference in New Issue
Block a user