-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadventuregamev2.html
396 lines (347 loc) · 11.5 KB
/
adventuregamev2.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<html>
<head>
<link rel="stylesheet" type="text/css" href="adventure.css">
<div style="font-family: 'adventureFontl';">
<!-- Remove Chrome outline of text field -->
<style type="text/css">
input:focus,
textarea:focus,
select:focus {
outline: none;
}
</style>
<!-- Makes text field border transparent -->
<style type="text/css">
input {
border: none;
background-color: transparent;
}
</style>
<script type = "text/javascript">
// game arrays //
var message = []
var rooms = ["room1", "room2", "room3", "room4"]
// Exits
var exits = new Array("E", "SWE", "WE", "SWE", "WE", "WE", "SWE", "WS",
"NSE", "SE", "WE", "NW", "SE", "W", "SNE", "NSW",
"NS", "NS", "SE", "WE", "NWE", "SWE", "WS", "N",
"N", "NWE", "NWE", "WE", "WE", "NW", "NE", "W");
// Objects in game
var GameObjects = new Array(" ", "Physics Notes", "Key Card", "Knife");
// new object for mapping object locations to items
var roomObjects = {999: "", 1: "Physics Notes", 2: "Key Card", 3: "Knife"}
// Inventory
var inventory = new Array();
console.log('[script definition] inventory', inventory)
//location of game objects - these objects relate to a array index - so Object[1] the Painting is located
//in rooms[2] the small garden - 999 indicates out of play
var objectLocations = [999, 1, 2, 3]
// Setting up game
var gameStart = message[0];
var gameEnd = message[1];
var gameForm = '<input type = "type" id = "answer" autofocus> <input type = "button" id = "enter" onclick="yourMove();" value = "enter" style="position: absolute; left: -9999px" />';
var room = 0;
var number = 0;
// The Game
function stuff()
{
// gameStart - room0
message[0] = "Do you want to play a game?";
// stage 1 - room1
message[1] = "You wake up. It's dark.";
// stage 1 - room1 (actions)
message[2] = "You get out of bed. You shiver as your bare feet touch the cold metal floor. You hear the soft continuous sound of rushing air. It's cold.";
message[3] = "It's dark, you can't see a thing.";
message[4] = "You use the bed frame to guide you through the darkness to the lightpanel by the door.";
message[5] = "The room fills with a synthetic red light. You can see now.</p>";
message[5] += "The room is flooded in a soft red glow. There's a <b>bed</b>, a small wooden <b>bedside table</b>, a large <b>dresser</b>, and a messy <b>desk</b> with a small lamp. A small <b>window</b> lies on the wall across from the bed.";
// stage 2 - room2 (actions)
message[7] = "No time for that now.";
message[8] = "The dresser has all of your clothes. Well, not your clothes - their clothes.</p>";
message[8] += "You're awake now. Might as well change.";
message[9] = "You change out of your sleeping garmets into the dark-red worksuit.";
message[10] = "The bed is modest. You wish they gave you more blankets.";
message[11] = "You aren't tired."
message[11] += message[6]
message[12] = "The desk is full of books, loose papers, and crumpled notes. A flouresent desk lamp you brought from home sits next to a framed picture.";
message[13] = "<i> Quantum Propulsion Theory. The Quandries of the Mathematical Universe. The Metaphysics of GIMPs.</i> </p>";
message[13] += "They are old and worn. Books were the only thing you were allowed to bring from home. </p> </br>";
message[13] += message[12];
message[14] = "Letters. The gilded insignia of the Interplanetary Alliance. </p>";
message[14] += message[12];
message[15] = "Equations. You're so close. They can't know. </p>";
message[15] += message[12];
message[16] = "That picture is the only thing that keeps you sane. It's: </p> </br>";
message[16] += " > <b>Mila</b>. On her first birthday. </p> </br> ";
message[16] += " > You and<b> Dr. Shevek </b>. Before the university shut down. </p> </br>";
message[16] += " > <b>Cyrus</b>. Smiling. </p> </br>";
message[17] = "Darkness.";
message[18] = "You see a red light start to flash through the small window in the door.";
message[19] = "You should grab your key card. You think it's on the bedside table.";
message[20] = "Your key card lies on the table. In bold letters it says your name. What's your full name?";
message[21] = "[name] - ACADEMIC GUEST.";
message[22] = "You pick up the key card.";
message[23] = "You walk over to the door. It slides open with a hiss.";
message[24] = "You walk over to the door. It's locked. You need your key card.";
// starting message
var respond = document.getElementById("messageBox");
var input = document.getElementById("inputForm");
// allows for 'enter' key to submit input & focuses on submit
input.addEventListener("keyup", function(event)
{
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("enter").click();
document.getElementById("answer").focus();
}
});
respond.innerHTML = message[0];
input.innerHTML = gameForm;
}
// this never executes...
if (inventory.length > 0) {
console.log('now')
// what is DisplayText?
// DisplayText("You are carrying: ");
var messageBox = document.getElementById("messageBox");
// this isn't working
messageBox.innerHtml = "You are carrying: ";
for (var i = 0; i < inventory.length ; i++) {
messageBox.append(inventory[i])
}
}
// Connecting user input
function yourMove()
{
respond = document.getElementById("messageBox");
input = document.getElementById('inputForm');
answer = document.getElementById("answer").value;
activeInventory = document.getElementById("inventoryList");
// roomTitle = document.getElementById("test");
// pick up object
function pickup (roomIndex) {
console.log('[pickup] roomIndex', roomIndex)
console.log('[pickup] objectLocations', objectLocations)
console.log('[pickup] inventory', inventory)
if (objectLocations[roomIndex] > 0 && objectLocations[roomIndex] < 1000) {
// to do:
// should i be able to pick up multiple of the same item?
// could increment the counter, or just not add it to the array if it's already in there
// probably just make the inventory also an object instead of an array
inventory.push(roomObjects[roomIndex])
console.log('[pickup] inventory', inventory);
}
}
// function scanRoomForItems(room){
// if(we find an item in the room, return the position of the item)
// }
function addItemToInventory(item) {
inventory.push(item)
}
//loops through the object location array and returns
function getObjectForRoom(room) {
console.log('room', room)
var roomIndex = -1;
for (var i = 0; i < objectLocations.length ; i++) {
if (objectLocations[i] == room)
roomIndex = i;
}
console.log('[getObjectForRoom] roomIndex',roomIndex)
return roomIndex
}
//Replaces the indexOf js function
function checkIndex(issFullArray, issToCheck) {
for (i = 0; i < issFullArray.length; i++) {
if (issFullArray[i] == issToCheck) {
return true;
}
}
return false;
}
// append the newly added item to the list
function updateInventoryScreen() {
//
console.log('updateInventory')
// to do: spaces between inventory items, right now it
// just prints the full array
activeInventory.innerHTML = "You are carrying: " + inventory
}
/////////////////////////////////////////////////
console.log('i is always undefined', i)
// to do: figure out what i thinks it's needed for
if (room == 0 && /y/i.test(answer))
{
number = 1;
room = 1;
}
/////////////////////////////////////////////////
if (room == 1 && /(stand)|(get up)/i.test(answer))
{
number = 2;
room = 1;
}
if (room == 1 && /(look)|(around)|(search)/i.test(answer))
{
number = 3;
room = 1;
}
if (room == 1 && /(find a)|(light)|(lamp)/i.test(answer))
{
number = 4;
room = 1;
}
if (room == 1 && /(turn)|(on)/i.test(answer))
{
number = 5;
room = 2;
}
/////////////////////////////////////////////////
if (room == 2 && /(dresser)/i.test(answer))
{
number = 8;
room = 2;
}
if (room == 2 && /(change)/i.test(answer))
{
number = 9;
room = 2;
}
if (room == 2 && /(bed)/i.test(answer))
{
number = 10;
room = 2;
}
if (room == 2 && /(sleep)|(go to bed)/i.test(answer))
{
number = 11;
room = 2;
}
if (room == 2 && /(desk)/i.test(answer))
{
number = 12;
room = 2;
}
if (room == 2 && /(books)/i.test(answer))
{
number = 13;
room = 2;
}
if (room == 2 && /(papers)/i.test(answer))
{
number = 14;
room = 2;
}
if (room == 2 && /(notes)/i.test(answer))
{
number = 15;
room = 2;
}
if (room == 2 && /(picture)|(frame)/i.test(answer))
{
number = 16;
room = 2;
}
if (room == 2 && /(Mila)|(Shevek)|(Cyrus)/i.test(answer))
{
number = 18;
room = 2;
}
if (room == 2 && /(go to door)|(outside)|(door)|(go)/i.test(answer))
{
number = 19;
room = 2;
}
if (room == 2 && /(table)|(bedside)/i.test(answer))
{
number = 20;
room = 2;
}
if (room == 2 && /(abbey)/i.test(answer))
{
number = 21;
room = 2;
}
if (room == 2 && /(take)|(key card)|(pick up)/i.test(answer))
{
pickup(room);
getObjectForRoom(room);
updateInventoryScreen()
number = 22;
room = 2;
}
if (room == 2 && /(open)|(door)|(go to door)/i.test(answer))
{
number = 23;
room = 2;
}
respond.innerHTML = message[number];
input.innerHTML = gameForm;
// updateInventory()
// activeInventory.innerHTML = (GameObjects[0]);
// roomTitle.innerHTML = (rooms[room]);
}
</script>
<!-- Formatting and uploading to page -->
<body onload = "stuff()">
<div id = "inventoryList"
style = "
width : 300px;
height: 500px;
margin: 0 auto;
position: fixed;
border: solid 1px red;
">
</div>
<!-- <div id = "test"
style = "
width : 300px;
height: 500px;
margin: 0 auto;
position: fixed;
border: solid 1px blue;
">
</div> -->
<div id = "container"
style = "
width : 600px;
height: 600px;
margin: 0 auto;
position: fixed;
top: 50%;
left: 35%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
">
<div id = "container"
style = "
width : 585px;
height: 100px;
margin: 0 auto;
position: absolute;
top: 30%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
overflow: auto;
">
<div id = "messageBox"
style = "
width : 585px;
margin: 0 auto;
position: relative;
overflow: auto;
">
</div>
</div>
<div id = "inputForm"
style = "
width : 560px;
height: 10px;
margin: 0 auto;
position: fixed;
top: 45%;
padding: 5px 5px 5px 1px;
">
</div>
</div>
</body>
</html>