mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-27 05:03:27 -08:00
Ported RUSSIAN ROULETTE to Javascript
This commit is contained in:
9
76 Russian Roulette/javascript/russianroulette.html
Normal file
9
76 Russian Roulette/javascript/russianroulette.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>RUSSIAN ROULETTE</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="russianroulette.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
93
76 Russian Roulette/javascript/russianroulette.js
Normal file
93
76 Russian Roulette/javascript/russianroulette.js
Normal file
@@ -0,0 +1,93 @@
|
||||
// RUSSIAN ROULETTE
|
||||
//
|
||||
// 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(28) + "RUSSIAN ROULETTE\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("THIS IS A GAME OF >>>>>>>>>>RUSSIAN ROULETTE.\n");
|
||||
restart = true;
|
||||
while (1) {
|
||||
if (restart) {
|
||||
restart = false;
|
||||
print("\n");
|
||||
print("HERE IS A REVOLVER.\n");
|
||||
}
|
||||
print("TYPE '1' TO SPIN CHAMBER AND PULL TRIGGER.\n");
|
||||
print("TYPE '2' TO GIVE UP.\n");
|
||||
print("GO");
|
||||
n = 0;
|
||||
while (1) {
|
||||
i = parseInt(await input());
|
||||
if (i == 2) {
|
||||
print(" CHICKEN!!!!!\n");
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
if (Math.random() > 0.833333) {
|
||||
print(" BANG!!!!! YOU'RE DEAD!\n");
|
||||
print("CONDOLENCES WILL BE SENT TO YOUR RELATIVES.\n");
|
||||
break;
|
||||
}
|
||||
if (n > 10) {
|
||||
print("YOU WIN!!!!!\n");
|
||||
print("LET SOMEONE ELSE BLOW HIS BRAINS OUT.\n");
|
||||
restart = true;
|
||||
break;
|
||||
}
|
||||
print("- CLICK -\n");
|
||||
print("\n");
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("...NEXT VICTIM...\n");
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user