- do {
- var x = Math.floor(Math.random()*(this.columns));
- var y = Math.floor(Math.random()*(this.rows));
- } while (!this.rooms[x][y].state);
- this.rooms[x][y].join();
- return player = new player(x,y);
+ $.getJSON(endpoint, { 'cmd' : 'join' }, function(json) {
+ self.player = new player(json.x, json.y, json.id);
+ setInterval(self.poll, 1000);
+ });
+ }
+
+ var commands = {
+ tell : function(msg) {
+ console.log(msg);
+ var parts = msg.match(/^(\w+)\s(.*)/);
+ if (!parts[1]) return;
+ var dest = parts[1];
+ msg = parts[2];
+// $.ajax({
+// url: endpoint,
+// data: { 'cmd' : 'tell', 'dest' : dest, 'msg' : msg },
+// success: function() {
+ writeToLog('You told ' + dest + ': ', 'tell', msg);
+// },
+// });
+ },
+ yell : function(msg) {
+ $.ajax({
+ url: endpoint,
+ data: { 'cmd' : 'yell', 'msg' : msg },
+ success: function() {
+ writeToLog('You yelled: ', 'yell', msg);
+ },
+ });
+ },
+ say : function(msg) {
+// $.ajax({
+// url: endpoint,
+// data: { 'cmd' : 'yell', 'msg' : msg },
+// success: function() {
+ writeToLog('You said: ', 'say', msg);
+// },
+// });
+ },
+ move : function(direction) {
+ this.player.move(direction);
+ },
+ }
+ function writeToLog(action, style, msg) {
+ $('#log').append(
+ $('<div>').addClass('logline').append(
+ $('<span>').addClass(style).text(action),
+ $('<span>').addClass('msg').text(msg)
+ )
+ )