mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
3
66_Number/javascript/README.md
Normal file
3
66_Number/javascript/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)
|
||||
9
66_Number/javascript/number.html
Normal file
9
66_Number/javascript/number.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>NUMBER</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="number.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
93
66_Number/javascript/number.js
Normal file
93
66_Number/javascript/number.js
Normal file
@@ -0,0 +1,93 @@
|
||||
// NUMBER
|
||||
//
|
||||
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
|
||||
//
|
||||
|
||||
function print(str)
|
||||
{
|
||||
document.getElementById("output").appendChild(document.createTextNode(str));
|
||||
}
|
||||
|
||||
function input()
|
||||
{
|
||||
var input_element;
|
||||
var input_str;
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
input_element = document.createElement("INPUT");
|
||||
|
||||
print("? ");
|
||||
input_element.setAttribute("type", "text");
|
||||
input_element.setAttribute("length", "50");
|
||||
document.getElementById("output").appendChild(input_element);
|
||||
input_element.focus();
|
||||
input_str = undefined;
|
||||
input_element.addEventListener("keydown", function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
input_str = input_element.value;
|
||||
document.getElementById("output").removeChild(input_element);
|
||||
print(input_str);
|
||||
print("\n");
|
||||
resolve(input_str);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function tab(space)
|
||||
{
|
||||
var str = "";
|
||||
while (space-- > 0)
|
||||
str += " ";
|
||||
return str;
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "NUMBER\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU\n");
|
||||
print("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO\n");
|
||||
print("A RANDOM NUMBER SELECTED BY THE COMPUTER.\n");
|
||||
print("\n");
|
||||
print("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)\n");
|
||||
print("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.\n");
|
||||
print("\n");
|
||||
p = 0;
|
||||
while (1) {
|
||||
do {
|
||||
print("GUESS A NUMBER FROM 1 TO 5");
|
||||
g = parseInt(await input());
|
||||
} while (g < 1 || g > 5) ;
|
||||
r = Math.floor(5 * Math.random() + 1);
|
||||
s = Math.floor(5 * Math.random() + 1);
|
||||
t = Math.floor(5 * Math.random() + 1);
|
||||
u = Math.floor(5 * Math.random() + 1);
|
||||
v = Math.floor(5 * Math.random() + 1);
|
||||
if (g == r) {
|
||||
p -= 5;
|
||||
} else if (g == s) {
|
||||
p += 5;
|
||||
} else if (g == t) {
|
||||
p += p;
|
||||
print("YOU HIT THE JACKPOT!!!\n");
|
||||
} else if (g == u) {
|
||||
p += 1;
|
||||
} else if (g == v) {
|
||||
p -= p * 0.5;
|
||||
}
|
||||
if (p <= 500) {
|
||||
print("YOU HAVE " + p + " POINTS.\n");
|
||||
print("\n");
|
||||
} else {
|
||||
print("!!!!YOU WIN!!!! WITH " + p + " POINTS.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user