Androtafl/assets/www/js/net.js
Wanja ff1ffc407d * Got rid of jo framework
* Using jqMobi as a javascript framework
* Using jqMobi-Ui as ui framework
* Implemented basic minimax AI
* Implemented minimalistic player pairing server for node.js
2012-04-06 01:54:53 +02:00

42 lines
No EOL
843 B
JavaScript

var TaflNet = {
connect: function(address) {
if (!address) address = "chrummibei.ch:47413";
var s = io.connect("http://"+address);
this.socket = s;
s.on('connect', function() {
s.emit('client.hello');
});
s.on('server.hello', function(data) {
s.emit('game.find_opponent');
});
s.on('game.start', function(data) {
TaflNet.on_game_start(data);
});
s.on('move.new', function(move) {
TaflNet.on_move(move);
});
s.on('game.end', function(data) {
TaflNet.on_game_end(data);
});
},
send_move: function(move) {
var s = this.socket;
if (! s)
throw "NotConnected";
s.emit('move.send', move);
},
on_game_start: function(data) {},
on_move: function(move) {},
on_game_end: function(data) {}
};