-
Notifications
You must be signed in to change notification settings - Fork 0
/
zorkington.js
94 lines (80 loc) · 2.21 KB
/
zorkington.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
let item
let items
let action
let actions
let valid_action
let inventory = {}
let current_room = "182 Main St"
let location = {
"182 Main St": {
description: function() {console.log("182 Main St.\nYou are standing on Main Street between Church and South Winooski\nThere is a door here. A keypad sits on the handle.\nOn the door is a handwritten sign.") },
"items": {
"sign": {
usage: ["read", "inspect", "examine" ],
description: function() {console.log("The sign says 'Welcome to Burlington Code Academy! Come on up to the second floor. If the door is locked, use the code 12345'")}
},
"test": {
usage:[0,1,2],
description: function(){console.log("testedtesting")}
},
"testing": "TESTING"
},
can_move_to: ["Foyer"]
}
//~ ,
//~ "Foyer": {
//~ description: function(){},
//~ items: {
//~ keypad: {
//~ usage: ["enter code", "enter password", "key in", "punch in", "enter"],
//~ description: "",
//~ keycode: 12345
//~ }
//~ },
//~ can_move_to: ["182 Main St", "Foyer"]
//~ }
}
function start() {
location[current_room].description()
process.stdin.on('data', (chunk) => {
user_input = chunk.toString().trim();
parse_input(user_input)
})
}
function parse_input(inp) {
input = inp.toLowerCase();
items = Object.keys(location[current_room]["items"])
items.forEach(function(e) {
if (input.includes(e)) {
item = e
}
})
if (item != undefined) {
actions = location[current_room]["items"][item]["usage"]
actions.forEach(function(e){
if (input.includes(e)) {
action = e
}
})
}
if (item === undefined) {
console.log("\nSorry, I don't know how to do that")
valid_action = false
} else if (item != undefined && action === undefined) {
console.log("\nSorry, I don't know how to use " + item + " that way")
console.log("\nAvailable actions for " + item + " are \n" + location[current_room]["items"][item]["usage"])
valid_action = false
} else if (item != undefined && action != undefined){
valid_action = true
} else {
console.log("\nSorry, I don't know how to do that")
valid_action = false
}
}
function clear_variables() {
item = undefined
action = undefined
actions = undefined
valid_action = undefined
}
start()