Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Merged
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
16 changes: 9 additions & 7 deletions mandatory/9-choose-your-own-adventure.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ let game = {
// to start in.
// Finish the function so that the currentRoom property is set to the room
// object for the correct room.
//
// Hint: the only valid rooms are "hall", "classroom" and "library".
},

move: function (direction) {
// This function is called with the direction that the player wants to move.
// Finish the function so that the currentRoom property is updated with new
// room in the direction that the player wants to move in.
//
// Hint: the room objects have north/east/south/west methods which return
// a new room object that is in the relevant direction.
},
Expand All @@ -62,7 +64,7 @@ DO NOT EDIT BELOW THIS LINE

let rooms = {
hall: {
name: "Hall",
name: "hall",
north: null,
east: function () {
return rooms.classroom;
Expand All @@ -73,7 +75,7 @@ let rooms = {
west: null,
},
classroom: {
name: "Classroom",
name: "classroom",
north: null,
east: null,
south: null,
Expand All @@ -82,7 +84,7 @@ let rooms = {
},
},
library: {
name: "Library",
name: "library",
north: function () {
return rooms.hall;
},
Expand Down Expand Up @@ -110,15 +112,15 @@ function start() {
function (room) {
game.start(room);
console.log("\n---------------------\n");
play();
play("start");
}
);
}

function play() {
function play(method) {
if (!game.currentRoom) {
throw new Error(
`It looks like the game hasn't been correctly started yet! Make sure your start method is correct`
`It looks like the game isn't quite right! Make sure your \`${method}\` method is correct`
);
}
console.log(`You are in the ${game.currentRoom.name}.\n`);
Expand All @@ -127,7 +129,7 @@ function play() {
function (direction) {
game.move(direction);
console.log("\n---------------------\n");
play();
play("move");
}
);
}
Expand Down