-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_zorkington.js
144 lines (116 loc) · 3.87 KB
/
test_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
let item
let items
let action
let actions
let specific_action
let valid_action
let inventory = {}
let current_room = "182 Main St"
let TEST
// NO functions inside the data structure. it's a lookup table. the functions outside the data structure interact with it.
// it should not interact with itself
//alternative data structure:
let actions = {
"take": ["take", "grab", "steal", "pick up"]
}
reverseActions = {}
for (action in actions) {
aliases = actions[action]
for (alias in aliases) {
reverseActions[alias] = action;
}
}
action = reverseActions[action]
// IMPORTANT: string.split(' ') WILL turn a longer string into an array where words are split between spaces and turned into an array
//"my dog has fleas".split(' ')
//[ 'my', 'dog', 'has', 'fleas' ]
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: {
actions: [
{name: ["read", "inspect", "examine"],
"take": ["take", "grab", "steal", "pick up"]
],
"used": false,
"taken": false,
"read_sign": () => { location[current_room]["items"][item]["usage"].description() },
"take_sign": function () { console.log("How are other students going to find their way?") }
},
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"]
}
}
function getKeyByValue(object, value) {
TEST = Object.keys(object).find(key => object[key] === value);
}
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 = Object.keys(location[current_room]["items"][item]["usage"]["actions"])
//~ if () {
//~ }
actions.forEach(function (e) {
let action_words = location[current_room]["items"][item]["usage"]["actions"][e]
//~ console.log(action_words + "action_words")
action_words.forEach(function (f) {
if (input.includes(f)) {
//~ action = location[current_room]["items"][item]["usage"]["actions"][0]
// var val = action_words.find(function (i) { return i.key == match })
// console.log(val)
action = f
console.log(action + " action")
//~ action = Object.keys(location[current_room]["items"][item]["usage"]["actions"][])
//~ console.log(location[])
//~ let test
//~ getKeyByValue(location[current_room]["items"][item]["usage"]["actions"], action)
//~ console.log(location[current_room]["items"][item]["usage"]["actions"])
//~ console.log(TEST)
}
})
})
}
//~ 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()