diff --git a/app.js b/app.js index d3b44a3..6c0fe1d 100644 --- a/app.js +++ b/app.js @@ -6,17 +6,54 @@ 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, + "south": go_south + }; 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; + } +} + +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 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