-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterface.js
More file actions
54 lines (46 loc) · 1.11 KB
/
interface.js
File metadata and controls
54 lines (46 loc) · 1.11 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
/**
* EverText (Now with lie-free cake!)
*/
/**
* Call this function to put HTML into the output box:
*/
function textOut(text)
{
var p = document.createElement("p");
p.innerHTML = text;
var output = document.getElementById("output");
output.appendChild(p);
if (output.scrollHeight) {
output.scrollTop = output.scrollHeight - 500;
}
}
/**
* Display a welcome message.
*/
function interfaceWelcome() {
textOut('<img alt="Welcome to EverText" src="welcome.png">');
doGame(['look']);
textOut('Type <em>help</em> if you need instructions.');
}
window.onload = interfaceWelcome;
/**
* Handle when the user presses "enter"
*/
function interfaceSubmit()
{
//Get the text they entered:
var inputBox = document.getElementById("input");
var input = inputBox.value;
inputBox.value = "";
//Write a copy of the text to the screen:
textOut('<kbd>> ' + input + '</kbd>');
//Tokenize the input string:
var tokens = input.toLowerCase().split(" ");
if (!tokens.length) {
textOut('You must enter some command.');
}
//Do some game stuff here:
doGame(tokens);
//All done:
return false;
}