-
Notifications
You must be signed in to change notification settings - Fork 1
/
adventure.html
368 lines (307 loc) · 11.7 KB
/
adventure.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
<!DOCTYPE html>
<html lang = 'en-US'>
<head>
<!--
WARNING: Internet Explorer is so outdated.
It won't work because of 'async'
-->
<meta charset = 'utf-8'>
<meta name = 'description' content = 'absolutely horrible and a waste of time'>
<meta name = 'keywords' content = 'adventure, fun, icecream'>
<meta name = 'author' content = 'icecream17'>
<title>adventure</title>
<style>
/* Probably the "same" [effect], but oh well */
/* Talking about the "html" and "body" */
/* The textarea "inherits" */
html, #story {
font-family: monospace;
font-size: large;
}
@keyframes startGameBackgroundTransition {
from {background-color: white;}
to {background-color: black;}
}
body {
background-color: white;
}
/* "Why are you using camelCase ugh that's not what you're..." */
#gameMenu {
color: white;
}
/* Dropdown from https://www.w3schools.com/howto/howto_css_dropdown.asp */
.dropdown {
position: absolute;
top: 10;
right: 10;
display: inline-block;
}
.dropdownContent {
display: none;
position: absolute;
top: 10;
right: 10;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdownContent button {
background-color: #1e90ff;
color: #fff;
padding: 12px 16px;
font-size: 16px;
border: none;
display: block;
}
.dropdownContent button:hover {background-color: #ddd;}
.dropdown:hover .dropdownContent {display: block;}
.dropdown:hover #gameMenu {background-color: #ddd;}
/* End of dropdown */
#story {
margin: 0;
}
#storyDiv {
width: 75%;
height: 75%;
overflow-y: auto;
border-right: 1px solid white;
border-bottom: 1px solid white;
}
#infoContainer {
position: absolute;
top: 10px;
left: 76%;
width: 23%;
border: 1px solid dodgerblue;
z-index: -1;
}
#playerInfo {
margin-top: 0;
padding-left: 1%;
border: 1px solid green;
}
#messageConsole {
margin-bottom: 0;
padding-left: 1%;
border: 1px solid red;
}
#playerConsoleContainer{
position: absolute;
bottom: 2%;
height: 22%;
width: 75%;
border-left: 1px solid orange;
}
#playerConsole {
margin-top: 0;
margin-left: 10px;
height: 100%;
width: 100%;
}
</style>
<!-- Jquery for the first time -->
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Icons from a font. Like menu. -->
<link rel = "stylesheet" href = "https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body>
<button onClick = "startGame()" type = "button" id = 'start'>Start game</button>
<button onClick = "continueGame()" type = "button" id = 'continue'>Continue</button>
</body>
<script>
let time;
let chapter = 0
let storyLine = 1 // Actual line - this is line 93
// This is line 94
const locations = [
"Office (Dallas)"
]
let Player = {
place: 0,
actions: 0, // location is a thing. no overwrite or error
lives: 10,
inventory: {}
}
/*
Credits:
Me (icecream17)
Test - JS.do
Search - Google
Menu icon - Google
JQuery - JQuery Foundation (hosted by Google)
[everything] Understanding - Stack Overflow, W3 Schools, MDN, Google
- CSS Understanding
- Animation Understanding
- Menu Dropdown
- Story scroll
- Async attempt
- HTML whitespace (computerhope.com)
*/
function startGame() {
time = new Date();
// Is there a better way?
// Warning: HTML whitespace rules sacrificed for good JS whitespace
document.body.innerHTML = (`
<div class = 'dropdown'>
<span class = "material-icons" id = 'gameMenu'>menu</span>
<div class = 'dropdownContent'>
<button id = 'menuInstructions' onClick = 'menu("menuInstructions")'>
Instructions </button>
<button id = 'menuSettings' onClick = 'menu("menuSettings")'>
Settings </button>
<button id = 'menuCredits' onClick = 'menu("menuCredits")'>
Credits </button>
</div>
</div>
<div id = 'storyDiv'>
<p id = 'story'>
</p>
</div>
<div id = 'infoContainer'>
<p id = 'playerInfo'></p>
<p id = 'messageConsole'></p>
</div>
<div id = 'playerConsoleContainer'>
<p id = 'playerConsole' contenteditable = 'true'></p>
</div>
`)
// Usually I like putting the => notation
setTimeout( function() {
writeToStory(`"Hi. Welcome to SideQuest" says the director. \n` +
`"There are only 3 challenges. Simple challenges,`
)
setTimeout ( function() {
writeToStory(`but they somehow take up the whole year.\n\nGood luck"\n` +
`\n\nA TV lights up saying "First Challenge: Go to Rowlett"\n\n` +
`What? That's really easy. Just 15 miles-ish!\n` +
`"SUPER FREE TREE APPLE!" a kid outside yells. gasp\n` +
`Your car is <em>missing!</em> ` +
`What used to be a crowded lot with no space\n` +
`is now replaced by an asteroid.\n\n` +
`<ol><li>What a boring presentation</li>` +
`<li>Wait... they told everyone to leave everything</li></ol>`
)
updateInfo()
$('#messageConsole').html('Welcome!')
$('#playerConsole').html('<em>></em>')
}, 2000)
}, 5000)
$('body').css({
'animation-name': 'startGameBackgroundTransition',
'animation-duration': '7s',
'animation-iteration-count': '1',
'animation-fill-mode': 'forwards',
'color': 'white'
})
$('story').css({
'animation-name': 'startGameBackgroundTransition',
'animation-duration': '7s',
'animation-iteration-count': '1',
'animation-fill-mode': 'forwards',
'color': 'white'
})
}
function continueGame() {
if ($('#potato').length) {
$('#continue').remove()
} else {
$('#continue').after(
'<p id = "potato">Sorry, this feature is currently unavailable</p>'
)
}
}
function menu(elementID) {
let messageElement = $('#messageConsole')
if (elementID === 'menuInstructions') {
messageElement.html('Click on the text links to play.<br><br>' +
'You can also type <em>help</em> in the "console", ' +
'which is the "orange" box at the bottom with the <em>></em> symbol<br><br>' +
'(Afterwards press Enter)'
)
} else if (elementID === 'menuSettings') {
} else if (elementID === 'menuCredits') {
} else {
}
}
console.clear()
function messageToStory (...messages) {
// wouldn't know how to write multiple things
}
function writeToStory (text, newline = '\n') {
async function avoidEncryption() {
await writeCharacters(text + newline)
}
function writeCharacters(string) {
let characters = string.split('')
for (let i = 0; i < characters.length; i++) {
if (characters[i] === '\n') {characters[i] === '<br>'}
}
// SOOO MANYYY PAOSSIBLE BUGGGGSSSSS!!!!!!!!!!!
for (let i = 0; i < characters.length; i++) {
if (characters[i] === '<' && characters[i + 1] !== ' ') {
debugger;
for (let j = i + 1; j < characters.length;) {
characters[i] += characters.splice(j, 1)
if (characters[i][characters[i].length - 1] === '>') {
break;
}
}
let endtag = '</' + characters[i].slice(1, Infinity)
let end = false
let possEndtag = ''
for (let j = i + 1; !end;) {
if (characters[j] === '<') {
possEndtag += characters[j]
}
if (possEndtag.length) {
if (characters[j] === endtag[possEndtag.length - 1]) {
possEndtag += characters[j]
} else {
possEndtag = ''
}
}
if (possEndtag === endtag) {
end = true
}
characters[i] += characters.splice(j, 1)
}
console.log(characters[i])
}
}
console.log(string, 'start')
return new Promise ( resolve => {
let writeCharacterByCharacter = setInterval( function () {
let nextCharacter = characters.shift()
$('#story').append(nextCharacter)
if (characters.length === 0) {
clearInterval(writeCharacterByCharacter)
resolve('done!')
}
}, 10)
}
)
}
function clickToContinue() {
// can't do this yet.
// would be soo great for suspense
}
// amazing
avoidEncryption()
}
function updateInfo() {
let info = `Player<br> location: ${locations[Player.place]} <br> ` +
`lives: ${Player.lives} <br> actions: ${Player.actions} <br> ` +
`time: ${new Date() - time} <br><br> Inventory <br>`
if (Object.keys(Player.inventory).length === 0) {
info += 'none'
} else {
for (let i of Object.keys(Player.inventory)) {
let keyInfo = `${i}: ${Player[i]} <br> `
info += keyInfo
}
}
$('#playerInfo').html(info)
}
</script>
<noscript>Somehow you don't have JavaScript - sorry.</noscript>
</html>