Permalink
Browse files

Merge branch 'master' of github.com:kek/mud

Conflicts:
	.gitignore
  • Loading branch information...
2 parents ac68f5f + d4f6eab commit e22df13ae9402d9c3da3137213c373e76474f26e @kek committed Aug 30, 2012
Showing with 211 additions and 115 deletions.
  1. +6 −2 README
  2. +2 −0 TODO
  3. +1 −1 app.js
  4. +9 −0 game/all.js
  5. +24 −3 game/dispatcher.js
  6. +12 −0 game/event.js
  7. +6 −9 game/game.js
  8. +29 −0 game/lists.js
  9. +17 −0 game/player.js
  10. +40 −0 game/room.js
  11. +16 −2 game/setup.js
  12. +6 −0 game/thing.js
  13. +4 −82 game/world.js
  14. +2 −2 package.json
  15. +0 −1 public/javascripts/client.js
  16. +9 −4 public/stylesheets/style.css
  17. +1 −2 test/{ → helpers}/mocks.js
  18. +27 −7 test/world-test.js
View
8 README
@@ -1,7 +1,11 @@
-Install node 0.6.17
+Install node
Run npm install
Run node app.js
-Visit http://localhost:19000/
+Visit http://localhost:19000/
+
+Testing:
+
+nodemon -w . -w game -w test app.js & vows *.js **/*.js **/*.jade -w
View
2 TODO
@@ -0,0 +1,2 @@
+http://backbonejs.org/
+http://ianstormtaylor.com/rendering-views-in-backbonejs-isnt-always-simple/
View
2 app.js
@@ -28,7 +28,7 @@ app.get('/', routes.index);
// Start
-game = require("./game");
+var game = require("./game");
if (require.main === module) {
app.listen(19000);
View
@@ -0,0 +1,9 @@
+module.exports = function(what) {
+ what.World = require('./world.js');
+ what.Room = require('./room.js');
+ what.Player = require('./player.js');
+ what.Dispatcher = require('./dispatcher.js');
+ what.Event = require('./event.js');
+ what.Thing = require('./thing.js');
+ what.ThingList = require('./lists.js').ThingList;
+}
View
@@ -17,6 +17,21 @@ var Dispatcher = function (actor) {
"help": function (complement) {
actor.message(Object.keys(verbs).join(", "));
+ },
+
+ "get": function (complement) {
+ thing = actor.room.things.findFirstByName(complement);
+ if (thing) {
+ actor.things.push(thing);
+ actor.message("You now have " + thing.name);
+ actor.room.things.splice(actor.room.things.indexOf(thing), 1);
+ } else {
+ actor.message("No such thing here.");
+ }
+ },
+
+ "inventory": function (complement) {
+ actor.message(actor.things.toString());
}
};
@@ -29,6 +44,14 @@ var Dispatcher = function (actor) {
};
});
+ actor.things.map(function (thing) {
+ Object.keys(thing.interactions).map(function (key) {
+ verbs[key] = function(complement) {
+ thing.interactions[key](actor, complement);
+ };
+ });
+ });
+
this.act = function (verb, complement) {
return verbs[verb](complement);
};
@@ -40,6 +63,4 @@ var Dispatcher = function (actor) {
};
Dispatcher.prototype = new Array();
-exports.extend = function(what) {
- what.Dispatcher = Dispatcher;
-}
+module.exports = Dispatcher;
View
@@ -0,0 +1,12 @@
+require('./all.js')(root);
+
+var Event = function (world, name, description) {
+ this.x = 1;
+
+ this.f = function () {
+ };
+
+ this.world.events.push(this);
+};
+
+module.exports = Event;
View
@@ -1,5 +1,4 @@
-require('./world').extend(root);
-require('./dispatcher').extend(root);
+require('../game/all.js')(root);
exports.start = function (io) {
var gameWorld = (require('./setup')).setupWorld();
@@ -13,25 +12,23 @@ exports.start = function (io) {
player.message(player.room.look());
socket.on('command', function (data) {
- input = data.command;
+ var input = data.command;
console.log(input);
- words = input.split(" ");
- verb = words.shift().toLowerCase();
- complement = words.join(" "); // words.join(" ");
+ var words = input.split(" ");
+ var verb = words.shift().toLowerCase();
+ var complement = words.join(" "); // words.join(" ");
var dispatcher = new Dispatcher(player);
player.message("> " + verb + " " + complement);
if(dispatcher.has(verb)) {
- dispatcher.act(verb, player, complement);
+ dispatcher.act(verb, complement);
} else {
socket.emit('news', { news: 'Unknown command.' });
}
-
});
});
};
-
View
@@ -0,0 +1,29 @@
+var ThingList = function () {
+ this.findFirstByName = function (name) {
+ return this.filter (function (t) {
+ return t.name == name;
+ })[0];
+ };
+
+ this.toString = function () {
+ return this.map(function (t) {
+ return t.name;
+ }).join(" ");
+ };
+
+ this.findByRoom = function (room) {
+ return this.filter (function (t) {
+ return t.room == room;
+ });
+ };
+};
+ThingList.prototype = new Array();
+
+exports.ThingList = ThingList;
+
+// ---
+//
+var RoomList = function () {
+};
+RoomList.prototype = new ThingList();
+
View
@@ -0,0 +1,17 @@
+require('./all.js')(root);
+
+var Player = function (room, socket) {
+ this.name = "Player" + Math.round(Math.random() * 1000);
+ this.room = room;
+ this.socket = socket;
+ this.things = new ThingList();
+
+ this.message = function (text) {
+ socket.emit('news', { news: text });
+ socket.emit('update', { field: 'room', value: this.room.name });
+ };
+
+ this.room.world.players.push(this);
+};
+
+module.exports = Player;
View
@@ -0,0 +1,40 @@
+require('./all.js')(root);
+
+var Exit = function (direction, room) {
+ this.room = room;
+ this.direction = direction;
+};
+
+var Room = function (world, name, description) {
+ this.exits = [];
+ this.name = name;
+ this.description = description;
+ this.world = world;
+ this.things = new ThingList();
+
+ this.addExit = function (direction, room) {
+ this.exits.push (new Exit(direction, room));
+ };
+
+ this.look = function () {
+ return this.name + "\n" + this.description + "\n" +
+ this.world.players.findByRoom(this).map(function (visitor) {
+ return visitor.name + " is here.\n";
+ }).join("") +
+ "Exits: " + this.exits.map(function (exit) {
+ return exit.direction;
+ }).join(" ") +
+ "\nThings: " + this.things.toString();
+ };
+
+ this.broadcast = function(actor, text) {
+ this.world.players.findByRoom(this).filter(function(p) {
+ return ( p != actor );
+ }).map(function (p) {
+ p.message(text);
+ });
+ };
+ this.world.rooms.push(this);
+};
+
+module.exports = Room;
View
@@ -1,13 +1,27 @@
-require('./world').extend(root);
+var World = require('./world');
+var Player = require('./player');
+var Room = require('./room');
exports.setupWorld = function () {
var world = new World();
var lobby = new Room(world, "The lobby", "You are standing in the lobby.");
var janitor = new Room(world, "The janitor's room", "This room is filled with cleaning tools.");
var graveyard = new Room(world, "The crypt", "You are dead.");
+ var wand = new Thing("wand",
+ { 'zap':
+ function(actor, complement) {
+ var newroom = new Room(world,
+ "A small cave",
+ "This room has been created by what seems to be a magic explosion.");
+ actor.room.addExit(complement, newroom);
+ newroom.addExit("back", actor.room);
+ }
+ });
+
+ lobby.things.push(wand);
lobby.addExit("north", janitor);
janitor.addExit("south", lobby);
graveyard.addExit("up", lobby);
return world;
-};
+};
View
@@ -0,0 +1,6 @@
+var Thing = function (name, interactions) {
+ this.name = name;
+ this.interactions = interactions;
+}
+
+module.exports = Thing;
View
@@ -1,86 +1,8 @@
-var ThingList = function () {
- this.findFirstByName = function (name) {
- return this.filter (function (p) {
- return p.name == name;
- })[0];
- };
-
- this.toString = function () {
- return this.map(function (p) {
- return p.name;
- }).join(" ");
- };
-};
-ThingList.prototype = new Array();
-
-var PlayerList = function () {
- this.findByRoom = function (room) {
- return this.filter (function (p) {
- return p.room == room;
- });
- };
-};
-PlayerList.prototype = new ThingList();
-
-var RoomList = function () {
-};
-RoomList.prototype = new ThingList();
-
-var Exit = function (direction, room) {
- this.room = room;
- this.direction = direction;
-};
-
-var Room = function (world, name, description) {
- this.exits = [];
- this.name = name;
- this.description = description;
- this.world = world;
-
- this.addExit = function (direction, room) {
- this.exits.push (new Exit(direction, room));
- };
-
- this.look = function () {
- return this.name + "\n" + this.description + "\n" +
- this.world.players.findByRoom(this).map(function (visitor) {
- return visitor.name + " is here.\n";
- }).join("") +
- "Exits: " + this.exits.map(function (exit) {
- return exit.direction;
- }).join(" ");
- };
-
- this.broadcast = function(actor, text) {
- this.world.players.findByRoom(this).filter(function(p) {
- return ( p != actor );
- }).map(function (p) {
- p.message(text);
- });
- };
- this.world.rooms.push(this);
-};
+require('../game/all.js')(root);
var World = function () {
- this.players = new PlayerList();
- this.rooms = new RoomList();
+ this.players = new ThingList();
+ this.rooms = new ThingList();
};
-var Player = function (room, socket) {
- this.name = "Player" + Math.round(Math.random() * 1000);
- this.room = room;
- this.socket = socket;
-
- this.message = function (text) {
- socket.emit('news', { news: text });
- socket.emit('update', { field: 'room', value: this.room.name });
- };
-
- this.room.world.players.push(this);
-};
-
-exports.extend = function(what) {
- what.Room = Room;
- what.Player = Player;
- what.World = World;
-};
+module.exports = World;
View
@@ -1,5 +1,5 @@
{
- "name": "socktest"
+ "name": "mud"
, "version": "0.0.1"
, "private": true
, "dependencies": {
@@ -8,4 +8,4 @@
, "socket.io": ">= 0.9.6"
, "vows": "> 0"
}
-}
+}
@@ -20,4 +20,3 @@ function submitCommand () {
socket.emit('command', {command: $('#command').val()});
$('#command').val("");
}
-
@@ -8,12 +8,18 @@ a {
#output {
border: 1px solid black;
- float: left;
- width: 50%;
+ background: #ac9;
+ color: #030;
}
#info {
- width: 50%;
+ position: fixed;
+ right: 8px;
+ top: 1em;
+ border: 1px solid black;
+ padding: 5px;
+ background: #efe;
+ color: #020;
}
#command {
@@ -23,4 +29,3 @@ a {
#command_form {
margin-bottom: 10px;
}
-
Oops, something went wrong.

0 comments on commit e22df13

Please sign in to comment.