-
Notifications
You must be signed in to change notification settings - Fork 5
/
numguess.wsf
64 lines (51 loc) · 1.4 KB
/
numguess.wsf
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
<?xml version="1.0" encoding="ISO-8859-1"?>
<job id="IncludeExample">
<script language="VBScript">
<![CDATA[
Function VBInputBox(prompt)
VBInputBox = InputBox(prompt)
End Function
]]>
</script>
<script language="JScript">
<![CDATA[
eval((new ActiveXObject("Scripting.FileSystemObject")).OpenTextFile("libnumguess.js", 1).ReadAll());
var isConsole = WScript.fullname.substr(WScript.fullname.length - 12) === '\\cscript.exe';
// Gets and returns a line of text with a prompt
var prompt;
if(isConsole) {
prompt = function(prompt_text) {
// Use the console for cscript
WScript.stdout.write(prompt_text + ' ');
return WScript.stdin.readline();
};
} else {
prompt = function(prompt_text) {
return VBInputBox(prompt_text);
};
}
var engine = NumGuessEngine;
engine.language = 'JScript';
engine.console = isConsole;
engine.show = function(s) {
WScript.echo(s);
};
engine.welcome();
var name = prompt('\nEnter your name:');
name = name || 'Player';
var limit = prompt('\nWelcome ' + name + ', enter upper limit:');
limit = parseInt(limit, 10) || 10;
engine.start(name, limit);
while(true) {
do {} while(!engine.guess(prompt('Guess:')))
var again = prompt('Play again [y/N]?')
if(again && again.toString().toUpperCase() == 'Y') {
engine.restart();
} else {
break;
}
}
WScript.echo('\nOkay, bye.');
]]>
</script>
</job>