Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions rooms/room1.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions rooms/room2.js
Original file line number Diff line number Diff line change
@@ -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;