-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathserver.js
More file actions
150 lines (141 loc) · 4.31 KB
/
Copy pathserver.js
File metadata and controls
150 lines (141 loc) · 4.31 KB
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
145
146
147
148
149
150
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.status(200);
res.sendFile(__dirname + "/index.html");
});
app.get('/:id', function(req, res){
if (req.params.id == "inventory") {
res.set({'Content-Type': 'application/json'});
res.status(200);
res.send(inventory);
return;
}
for (var i in campus) {
if (req.params.id == campus[i].id) {
res.set({'Content-Type': 'application/json'});
res.status(200);
res.send(campus[i]);
return;
}
}
res.status(404);
res.send("not found, sorry");
});
app.get('/images/:name', function(req, res){
res.status(200);
res.sendFile(__dirname + "/" + req.params.name);
});
app.delete('/:id/:item', function(req, res){
for (var i in campus) {
if (req.params.id == campus[i].id) {
res.set({'Content-Type': 'application/json'});
var ix = -1;
if (campus[i].what != undefined) {
ix = campus[i].what.indexOf(req.params.item);
}
if (ix >= 0) {
res.status(200);
inventory.push(campus[i].what[ix]); // stash
res.send(inventory);
campus[i].what.splice(ix, 1); // room no longer has this
return;
}
res.status(200);
res.send([]);
return;
}
}
res.status(404);
res.send("location not found");
});
app.put('/:id/:item', function(req, res){
for (var i in campus) {
if (req.params.id == campus[i].id) {
// Check you have this
var ix = inventory.indexOf(req.params.item)
if (ix >= 0) {
dropbox(ix,campus[i]);
res.set({'Content-Type': 'application/json'});
res.status(200);
res.send([]);
} else {
res.status(404);
res.send("you do not have this");
}
return;
}
}
res.status(404);
res.send("location not found");
});
app.listen(3000);
var dropbox = function(ix,room) {
var item = inventory[ix];
inventory.splice(ix, 1); // remove from inventory
if (room.id == 'allen-fieldhouse' && item == "basketball") {
room.text += " Someone found the ball so there is a game going on!"
return;
}
if (room.what == undefined) {
room.what = [];
}
room.what.push(item);
}
var inventory = ["laptop"];
var campus =
[ { "id": "lied-center",
"where": "LiedCenter.jpg",
"next": {"east": "eaton-hall", "south": "dole-institute"},
"text": "You are outside the Lied Center."
},
{ "id": "dole-institute",
"where": "DoleInstituteofPolitics.jpg",
"next": {"east": "allen-fieldhouse", "north": "lied-center"},
"text": "You take in the view of the Dole Institute of Politics. This is the best part of your walk to Nichols Hall."
},
{ "id": "eaton-hall",
"where": "EatonHall.jpg",
"next": {"east": "snow-hall", "south": "allen-fieldhouse", "west": "lied-center"},
"text": "You are outside Eaton Hall. You should recognize here."
},
{ "id": "snow-hall",
"where": "SnowHall.jpg",
"next": {"east": "strong-hall", "south": "ambler-recreation", "west": "eaton-hall"},
"text": "You are outside Snow Hall. Math class? Waiting for the bus?"
},
{ "id": "strong-hall",
"where": "StrongHall.jpg",
"next": {"east": "outside-fraser", "north": "memorial-stadium", "west": "snow-hall"},
"what": ["coffee"],
"text": "You are outside Stong Hall."
},
{ "id": "ambler-recreation",
"where": "AmblerRecreation.jpg",
"next": {"west": "allen-fieldhouse", "north": "snow-hall"},
"text": "It's the starting of the semester, and you feel motivated to be at the Gym. Let's see about that in 3 weeks."
},
{ "id": "outside-fraser",
"where": "OutsideFraserHall.jpg",
"next": {"west": "strong-hall","north":"spencer-museum"},
"what": ["basketball"],
"text": "On your walk to the Kansas Union, you wish you had class outside."
},
{ "id": "spencer-museum",
"where": "SpencerMuseum.jpg",
"next": {"south": "outside-fraser","west":"memorial-stadium"},
"what": ["art"],
"text": "You are at the Spencer Museum of Art."
},
{ "id": "memorial-stadium",
"where": "MemorialStadium.jpg",
"next": {"south": "strong-hall","east":"spencer-museum"},
"what": ["ku flag"],
"text": "Half the crowd is wearing KU Basketball gear at the football game."
},
{ "id": "allen-fieldhouse",
"where": "AllenFieldhouse.jpg",
"next": {"north": "eaton-hall","east": "ambler-recreation","west": "dole-institute"},
"text": "Rock Chalk! You're at the field house."
}
]