mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-27 13:14:15 -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
51_Hurkle/javascript/README.md
Normal file
3
51_Hurkle/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
51_Hurkle/javascript/hurkle.html
Normal file
9
51_Hurkle/javascript/hurkle.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>HURKLE</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="hurkle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
102
51_Hurkle/javascript/hurkle.js
Normal file
102
51_Hurkle/javascript/hurkle.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// BATNUM
|
||||
//
|
||||
// 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) + "HURKLE\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
n = 5;
|
||||
g = 10;
|
||||
print("\n");
|
||||
print("A HURKLE IS HIDING ON A " + g + " BY " + g + " GRID. HOMEBASE\n");
|
||||
print("ON THE GRID IS POINT 0,0 IN THE SOUTHWEST CORNER,\n");
|
||||
print("AND ANY POINT ON THE GRID IS DESIGNATED BY A\n");
|
||||
print("PAIR OF WHOLE NUMBERS SEPERATED BY A COMMA. THE FIRST\n");
|
||||
print("NUMBER IS THE HORIZONTAL POSITION AND THE SECOND NUMBER\n");
|
||||
print("IS THE VERTICAL POSITION. YOU MUST TRY TO\n");
|
||||
print("GUESS THE HURKLE'S GRIDPOINT. YOU GET " + n + " TRIES.\n");
|
||||
print("AFTER EACH TRY, I WILL TELL YOU THE APPROXIMATE\n");
|
||||
print("DIRECTION TO GO TO LOOK FOR THE HURKLE.\n");
|
||||
print("\n");
|
||||
while (1) {
|
||||
a = Math.floor(g * Math.random());
|
||||
b = Math.floor(g * Math.random());
|
||||
for (k = 1; k <= n; k++) {
|
||||
print("GUESS #" + k + " ");
|
||||
str = await input();
|
||||
x = parseInt(str);
|
||||
y = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
if (x == a && y == b) {
|
||||
print("\n");
|
||||
print("YOU FOUND HIM IN " + k + " GUESSES!\n");
|
||||
break;
|
||||
}
|
||||
print("GO ");
|
||||
if (y < b) {
|
||||
print("NORTH");
|
||||
} else if (y > b) {
|
||||
print("SOUTH");
|
||||
}
|
||||
if (x < a) {
|
||||
print("EAST\n");
|
||||
} else {
|
||||
print("WEST\n");
|
||||
}
|
||||
}
|
||||
if (k > n) {
|
||||
print("\n");
|
||||
print("SORRY, THAT'S " + n + " GUESSES.\n");
|
||||
print("THE HURKLE IS AT " + a + "," + b + "\n");
|
||||
}
|
||||
print("\n");
|
||||
print("LET'S PLAY AGAIN, HURKLE IS HIDING.\n");
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user