mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-26 04:41:52 -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:
9
93_23_Matches/javascript/23matches.html
Normal file
9
93_23_Matches/javascript/23matches.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>23 MATCHES</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="23matches.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
122
93_23_Matches/javascript/23matches.js
Normal file
122
93_23_Matches/javascript/23matches.js
Normal file
@@ -0,0 +1,122 @@
|
||||
// 23 MATCHES
|
||||
//
|
||||
// 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 control section
|
||||
async function main()
|
||||
{
|
||||
print(tab(31) + "23 MATCHES\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print(" THIS IS A GAME CALLED '23 MATCHES'.\n");
|
||||
print("\n");
|
||||
print("WHEN IT IS YOUR TURN, YOU MAY TAKE ONE, TWO, OR THREE\n");
|
||||
print("MATCHES. THE OBJECT OF THE GAME IS NOT TO HAVE TO TAKE\n");
|
||||
print("THE LAST MATCH.\n");
|
||||
print("\n");
|
||||
print("LET'S FLIP A COIN TO SEE WHO GOES FIRST.\n");
|
||||
print("IF IT COMES UP HEADS, I WILL WIN THE TOSS.\n");
|
||||
print("\n");
|
||||
n = 23;
|
||||
q = Math.floor(2 * Math.random());
|
||||
if (q != 1) {
|
||||
print("TAILS! YOU GO FIRST. \n");
|
||||
print("\n");
|
||||
} else {
|
||||
print("HEADS! I WIN! HA! HA!\n");
|
||||
print("PREPARE TO LOSE, MEATBALL-NOSE!!\n");
|
||||
print("\n");
|
||||
print("I TAKE 2 MATCHES\n");
|
||||
n -= 2;
|
||||
}
|
||||
while (1) {
|
||||
if (q == 1) {
|
||||
print("THE NUMBER OF MATCHES IS NOW " + n + "\n");
|
||||
print("\n");
|
||||
print("YOUR TURN -- YOU MAY TAKE 1, 2 OR 3 MATCHES.\n");
|
||||
}
|
||||
print("HOW MANY DO YOU WISH TO REMOVE ");
|
||||
while (1) {
|
||||
k = parseInt(await input());
|
||||
if (k <= 0 || k > 3) {
|
||||
print("VERY FUNNY! DUMMY!\n");
|
||||
print("DO YOU WANT TO PLAY OR GOOF AROUND?\n");
|
||||
print("NOW, HOW MANY MATCHES DO YOU WANT ");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
n -= k;
|
||||
print("THERE ARE NOW " + n + " MATCHES REMAINING.\n");
|
||||
if (n == 4) {
|
||||
z = 3;
|
||||
} else if (n == 3) {
|
||||
z = 2;
|
||||
} else if (n == 2) {
|
||||
z = 1;
|
||||
} else if (n > 1) {
|
||||
z = 4 - k;
|
||||
} else {
|
||||
print("YOU WON, FLOPPY EARS !\n");
|
||||
print("THINK YOU'RE PRETTY SMART !\n");
|
||||
print("LETS PLAY AGAIN AND I'LL BLOW YOUR SHOES OFF !!\n");
|
||||
break;
|
||||
}
|
||||
print("MY TURN ! I REMOVE " + z + " MATCHES\n");
|
||||
n -= z;
|
||||
if (n <= 1) {
|
||||
print("\n");
|
||||
print("YOU POOR BOOB! YOU TOOK THE LAST MATCH! I GOTCHA!!\n");
|
||||
print("HA ! HA ! I BEAT YOU !!!\n");
|
||||
print("\n");
|
||||
print("GOOD BYE LOSER!\n");
|
||||
break;
|
||||
}
|
||||
q = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
main();
|
||||
3
93_23_Matches/javascript/README.md
Normal file
3
93_23_Matches/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)
|
||||
Reference in New Issue
Block a user