From 6b63030268ecc12c92e1644a8d6822b9f5f87d16 Mon Sep 17 00:00:00 2001 From: Alessandro Braidotti Date: Fri, 21 Jul 2017 21:48:48 -0400 Subject: [PATCH 1/2] add rooms and basic movement --- app.js | 28 +++++++++++++++++++++++++--- rooms/room1.js | 7 +++++++ rooms/room2.js | 7 +++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 rooms/room1.js create mode 100644 rooms/room2.js diff --git a/app.js b/app.js index d3b44a3..1c6382b 100644 --- a/app.js +++ b/app.js @@ -6,17 +6,39 @@ const cli = require("./CLI"); const rl = cli.rl; const print = cli.print; -// add fuctions +// add functions const example = require("./example.js"); +const room1 = require("./rooms/room1.js").room1; +const room2 = require("./rooms/room2.js").room2; + +const rooms = {"starting_room":room1, "smooth_corridor":room2}; + +let current_room = room1; + const commands = { "hello": () => {print("world!\n");}, - "look": () => {print("You stare into the void.\n");}, + "look": () => {print("You are in " + current_room.name + "\n" );}, "quit": () => {rl.close();}, "exit": () => {rl.close();}, "help": function(){print("I respond to the following commands: " + (Object.keys(this)).join(", ") + "\n");}, - "test": example.example + "test": example.example, + + "north": go_north, + }; cli.activateCLI(commands); + +function go_north(){ + var exits = Object.keys(current_room.exits); + print("Going north.\n"); + print(exits + "\n"); + if (exits.includes("north")){ + var new_room_name = current_room.exits.north; + print("arrived.\n"); + var new_room = rooms["smooth_corridor"]; + current_room = new_room; + } +} \ No newline at end of file diff --git a/rooms/room1.js b/rooms/room1.js new file mode 100644 index 0000000..c748e6a --- /dev/null +++ b/rooms/room1.js @@ -0,0 +1,7 @@ +var room1 = { + name: "starting_room", + description: "You stand in a dark cavern. There is a trickle of water on the far wall.", + exits: {north: "smooth_corridor"} + } + + exports.room1 = room1; \ No newline at end of file diff --git a/rooms/room2.js b/rooms/room2.js new file mode 100644 index 0000000..5b192ec --- /dev/null +++ b/rooms/room2.js @@ -0,0 +1,7 @@ +var room2 = { + name: "smooth_corridor", + description: "You find yourself in a narrow, smooth corridor.", + exits: {south: "starting_room"} + } + + exports.room2 = room2; \ No newline at end of file From b7540bfe0490313a062194b5f210e73619a57428 Mon Sep 17 00:00:00 2001 From: Alessandro Braidotti Date: Sun, 23 Jul 2017 10:00:09 -0400 Subject: [PATCH 2/2] add south command --- app.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 1c6382b..6c0fe1d 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,9 @@ const example = require("./example.js"); const room1 = require("./rooms/room1.js").room1; const room2 = require("./rooms/room2.js").room2; -const rooms = {"starting_room":room1, "smooth_corridor":room2}; +const rooms = {"starting_room":room1, + "smooth_corridor":room2 + }; let current_room = room1; @@ -24,7 +26,8 @@ const commands = { "help": function(){print("I respond to the following commands: " + (Object.keys(this)).join(", ") + "\n");}, "test": example.example, - "north": go_north, + "north": go_north, + "south": go_south }; @@ -41,4 +44,16 @@ function go_north(){ var new_room = rooms["smooth_corridor"]; current_room = new_room; } +} + +function go_south(){ + var exits = Object.keys(current_room.exits); + print("Going south.\n"); + print(exits + "\n"); + if (exits.includes("south")){ + var new_room_name = current_room.exits.south; + print("arrived.\n"); + var new_room = rooms["starting_room"]; + current_room = new_room; + } } \ No newline at end of file