From: Dylan Lloyd Date: Wed, 28 Aug 2013 04:55:21 +0000 (+0000) Subject: bind chat commands X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=93ee0b987b1558436cb0333640d32c87299097ca;p=mudd.git bind chat commands --- diff --git a/index.php b/index.php index d3a0974..8321f4d 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,6 @@ -
submit
+
submit
diff --git a/mud.js b/mud.js index eb1b55c..1017af9 100644 --- a/mud.js +++ b/mud.js @@ -11,6 +11,7 @@ $(document).ready(function(){ var rooms = mud.rooms; switch (direction) { case 'left': + case 'west': if (rooms[this.x-1] && rooms[this.x-1][this.y] && !rooms[this.x-1][this.y].state) { rooms[this.x][this.y].clear(); @@ -19,6 +20,7 @@ $(document).ready(function(){ } break; case 'up': + case 'north': if (rooms[this.x][this.y-1] && !rooms[this.x][this.y-1].state) { rooms[this.x][this.y].clear(); @@ -27,6 +29,7 @@ $(document).ready(function(){ } break; case 'right': + case 'east': if (rooms[this.x+1] && rooms[this.x+1][this.y+1] && !rooms[this.x+1][this.y].state) { rooms[this.x][this.y].clear(); @@ -35,6 +38,7 @@ $(document).ready(function(){ } break; case 'down': + case 'south': if (rooms[this.x][this.y+1] && !rooms[this.x][this.y+1].state) { rooms[this.x][this.y].clear(); @@ -58,7 +62,6 @@ $(document).ready(function(){ this.state = 1; } this.clear = function() { - console.log('clearing'); c.fillStyle = "rgb(255,255,255)"; c.fillRect(this.x, this.y, this.h, this.l); this.state = 0; @@ -128,6 +131,28 @@ $(document).ready(function(){ } e.preventDefault(); }); + + var commands = { + tell : function() {}, + yell : function() {}, + move : function(direction) { + player.move(direction); + }, + } + $('#submit').click(function() { + var text = $('#chat').val(); + var parts = text.match(/^(\w+)\s(.*)/); + var cmd = parts[1]; + text = parts[2]; + if (commands[cmd] != undefined) commands[cmd](text); + }); + $('#chat').keypress(function(e) { + if (e.which == '13') { + $('#submit').click(); + $('#chat').val(''); + } + }); + } var mud = new universe;