-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathacode.html
More file actions
281 lines (278 loc) · 8.1 KB
/
acode.html
File metadata and controls
281 lines (278 loc) · 8.1 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
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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
%JAVASCRIPT%
var moveLimit = 200;
var compact = 0;
var rType = 0;
var turn = 0;
var hpos = 0
var hsiz = 0;
var hcom = [];
var conbot = 0;
var advtext = 0;
var advcom = 0;
var started = 0;
var gameInfo;
var advTurn = Module.cwrap('advturn', 'string', ['string']);
function scrollit()
{ window.scrollTo(0, conbot.offsetTop); }
function writeit(text)
{ var newDiv = document.createElement('div'); newDiv.id = 'chunk';
newDiv.setAttribute('name', 'chunk'); newDiv.innerHTML = text;
document.getElementById('advtext').insertBefore(newDiv, null); scrollit(); }
function zapit()
{ document.getElementById('comform').innerHTML = ''; }
function shutit(text)
{
zapit();
writeit(text + '<form><div align=center>' +
'<input style="color:red;font-size:110%" onclick="javascript:location.reload()"' +
'type="button" value="Play again" /><br>or<br>' +
'<input class="custom-button" onclick="javascript:self.close()" ' +
'type="button" value="Close this tab/window" /><br>' +
'<span class="red">This button will only work if your ' +
' browser<br> is not being paranoid about security.</span></p>' +
'</div></form>');
}
function init()
{
FS.mkdir('/%NAME%');
FS.mount(IDBFS, {}, '/%NAME%');
FS.chdir('/%NAME%');
FS.syncfs(true, init2);
}
function init2(err)
{
if (err)
{ alert("IDBFS error: " + err) }
else
{
conbot = document.getElementById('conbot');
advtext = document.getElementById('advtext');
advcom = document.getElementById('advcom');
gameInfo = advTurn('_INFO_HTML_').split('|');
document.title = gameInfo[0];
document.getElementById('gameid').innerHTML = gameInfo[1];
var gameList = advTurn('_LIST_').split('|');
var savedGames = document.getElementById('saved');
var count = 0;
var first = 1;
if (gameList.length > 0)
{
for (var i = 0; i < gameList.length; i++)
{
if (!gameList[i]) continue;
document.getElementById('youcan').style.display = 'inline';
if (gameList[i].match(/^\./))
{ document.getElementById('resume').style.display = 'inline' }
else if (gameInfo[0] == 'Adv550' || gameInfo[0] == 'Adv660')
{
if (first)
{
first = 0;
savedGames.innerHTML += '<br> <br>' + gameInfo[0] +
' does not support loading a saved game at start, but you ' +
'have the following saved games:';
}
savedGames.innerHTML +=
(count == 0 ? '<br>' : '  ') +
'<b>' + gameList[i] + '</b>';
if (++count == 5)
count = 0;
if (i < gameList.length - 1)
savedGames.innerHTML += ', ';
}
else
{
if (first)
{
first = 0;
savedGames.innerHTML += '<br>or load a saved game:';
}
savedGames.innerHTML +=
(count == 0 ? '<br>' : '  ') +
'<input type=button class=query ' +
"value='" + gameList[i] + "' " + 'onclick="javascript:startit(' +
"'_LOAD_" + gameList[i] + "'" + ')">';
if (++count == 5)
count = 0;
}
}
}
}
}
function keyDown(ev)
{
var e = ev;
var code = (e.charCode || e.keyCode);
if (code == 16)
return false;
if (code == 13)
{
doit('');
return false;
}
if (code == 38 || code == 187 || code == 107)
code = 1;
else if (code == 40 || code == 189 || code == 109)
code = -1;
else
code = 0;
if (code != 0)
hist(code);
return false;
}
function hist(step)
{
var h = 2 * hpos;
hcom[h] = advcom.value;
hpos += step;
if (hpos < 0) hpos = 0;
if (hpos > hsiz) hpos = hsiz;
h = 2 * hpos;
if (! hcom[h + 1])
hcom[h + 1] = hcom[h];
advcom.value = hcom[h];
advcom.focus();
return;
}
function showit(text)
{
var type = text.substr(0, 1);
if (type != 'k')
{
rType = type;
writeit(text.substr(1));
if (type == 'f')
shutit('');
else if (started)
advcom.focus();
FS.syncfs(function(error) {
if (error)
alert("Error while syncing" + error);
});
}
}
function doit(cmd)
{
var com = advcom.value;
var pars;
turn++;
hcom[0] = com;
var prompt = document.getElementById('prompt');
if (prompt)
{
var el = document.createElement('span');
var tx = (rType == 'q' || rType == 'm' ||
rType == 'r' || rType == 's') ?
prompt.innerHTML : '?';
if (rType == 'c') tx = '<br>?';
el.className = 'query';
el.innerHTML = tx + ' ' + com +
(rType == 't' ? '<br> <br>' : '');
prompt.parentNode.replaceChild(el, prompt);
el = null;
}
advcom.value = '';
if (com && ! com.match(/^_/))
{
var i;
for (i = 1; i < hcom.length; i += 2)
{
if (hcom[i])
{
hcom[i - 1] = hcom[i];
hcom[i] = '';
}
}
if (hcom[0] == hcom[2])
hcom[0] = '';
else
{
hcom.unshift('');
hcom.unshift('');
hsiz++;
}
}
hpos = 0;
if (cmd) com = cmd
else if (started == 0)
com = '_START_';
showit(advTurn(com));
started = 1;
var kids = document.getElementsByName('chunk');
if (kids.length > moveLimit)
{
kids[0].parentNode.removeChild(kids[0]);
hcom.pop();
hcom.pop();
hsiz--;
}
}
function startit(what)
{
document.getElementById('startit').style.display = 'none';
document.getElementById('gameview').style.display = 'block';
document.getElementById('advcom').focus();
advcom.value = what;
doit(what);
}
</script>
<style type="text/css">
table.main{max-width:900px; width:98%}
*.query{color:red}
*.debug{color:blue}
*.red{color:red}
*,input{color:black}
td,input{background-color:#d0e0ff}
input.advcom{width:60%;border: 1px inset #666666}
</style>
</head>
<body onload="javascript:init();" bgcolor="#222222" text="black">
<table class=main id=frame align="center" border="1" cellpadding="16">
<tbody>
<tr>
<td style="vertical-align:top">
<div id="startit">
<h2 align="center" id=gameid></h2>
<p>The game can be played entirely from the keyboard, as long as the
command input field remains in focus. Commands can be submitted by
pressing the ENTER key (a.k.a. RETURN or GO). Up and down arrow keys
allow recalling/selecting previous commands. If you wish to stop
playing and to continue at some other time, it is not necessary to use
the save command – just open this page again and you will be offered
the option of continuing the current game, if there is one. The game runs
locally on your machine – there is no network access. All data
storage relies on your browser's sand-boxed data store.</p>
</p><p align="center"><span id=youcan style="display:none">You can<br></span>
<span id=resume style="display:none">
<input value="Continue your game" class=query
onclick="javascript:startit('_RESUME_')" type="button"> or </span>
<input id=playit value="Start a new game" class="query"
onclick="javascript:startit('_START_')" type="button">
<span id=saved></span>
</p>
<p>If you have any problems getting the game working or with the game
itself, please feel free to drop me a line at <i><b>mla@mipmip.org</b></i>.</p>
<p align=center>This JavaScript version of the game is made possible by
the magic of <b>Emscripten</b><br>
(<a href="http://kripken.github.io/emscripten-site/"><i>http://kripken.github.io/emscripten-site/</i></a>).
</div>
<div id="gameview" style="display:none">
<div id="advtext"></div>
<span id="comform"><span class="query">? </span>
<input class="advcom" onkeydown="javascript:keyDown(event)"
id="advcom" maxlength="160" type="text">
<button onclick="javascript:doit('')">Submit</button>
 <button onclick="javascript:hist(1)">↑</button>
 <button onclick="javascript:hist(-1)">↓</button>
</span><br></div><div id="conbot"></div>
</td></tr></tbody></table>
</body></html>