mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-27 21:23:30 -08:00
Merge pull request #96 from nanochess/main
Ported BOWLING, BOXING and BUG to Javascript
This commit is contained in:
9
14 Bowling/javascript/bowling.html
Normal file
9
14 Bowling/javascript/bowling.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>BOWLING</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="bowling.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
179
14 Bowling/javascript/bowling.js
Normal file
179
14 Bowling/javascript/bowling.js
Normal file
@@ -0,0 +1,179 @@
|
||||
// BOWLING
|
||||
//
|
||||
// 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(34) + "BOWL\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
c = [];
|
||||
a = [];
|
||||
for (i = 0; i <= 15; i++)
|
||||
c[i] = 0;
|
||||
print("WELCOME TO THE ALLEY\n");
|
||||
print("BRING YOUR FRIENDS\n");
|
||||
print("OKAY LET'S FIRST GET ACQUAINTED\n");
|
||||
print("\n");
|
||||
print("THE INSTRUCTIONS (Y/N)\n");
|
||||
str = await input();
|
||||
if (str.substr(0, 1) == "Y") {
|
||||
print("THE GAME OF BOWLING TAKES MIND AND SKILL.DURING THE GAME\n");
|
||||
print("THE COMPUTER WILL KEEP SCORE.YOU MAY COMPETE WITH\n");
|
||||
print("OTHER PLAYERS[UP TO FOUR].YOU WILL BE PLAYING TEN FRAMES\n");
|
||||
print("ON THE PIN DIAGRAM 'O' MEANS THE PIN IS DOWN...'+' MEANS THE\n");
|
||||
print("PIN IS STANDING.AFTER THE GAME THE COMPUTER WILL SHOW YOUR\n");
|
||||
print("SCORES .\n");
|
||||
}
|
||||
print("FIRST OF ALL...HOW MANY ARE PLAYING");
|
||||
r = parseInt(await input());
|
||||
while (1) {
|
||||
print("\n");
|
||||
print("VERY GOOD...\n");
|
||||
for (i = 1; i <= 100; i++) {
|
||||
a[i] = [];
|
||||
for (j = 1; j <= 6; j++)
|
||||
a[i][j] = 0;
|
||||
}
|
||||
f = 1;
|
||||
do {
|
||||
for (p = 1; p <= r; p++) {
|
||||
// m = 0; // Repeated in original
|
||||
b = 1;
|
||||
m = 0;
|
||||
q = 0;
|
||||
for (i = 1; i <= 15; i++)
|
||||
c[i] = 0;
|
||||
while (1) {
|
||||
// Ball generator using mod '15' system
|
||||
print("TYPE ROLL TO GET THE BALL GOING.\n");
|
||||
ns = await input();
|
||||
k = 0;
|
||||
d = 0;
|
||||
for (i = 1; i <= 20; i++) {
|
||||
x = Math.floor(Math.random() * 100);
|
||||
for (j = 1; j <= 10; j++)
|
||||
if (x < 15 * j)
|
||||
break;
|
||||
c[15 * j - x] = 1;
|
||||
}
|
||||
// Pin diagram
|
||||
print("PLAYER: " + p + " FRAME: " + f + " BALL: " + b + "\n");
|
||||
print("\n");
|
||||
for (i = 0; i <= 3; i++) {
|
||||
str = "";
|
||||
for (j = 1; j <= 4 - i; j++) {
|
||||
k++;
|
||||
while (str.length < i)
|
||||
str += " ";
|
||||
if (c[k] == 1)
|
||||
str += "O ";
|
||||
else
|
||||
str += "+ ";
|
||||
}
|
||||
print(str + "\n");
|
||||
}
|
||||
// Roll analysis
|
||||
for (i = 1; i <= 10; i++)
|
||||
d += c[i];
|
||||
if (d - m == 0)
|
||||
print("GUTTER!!\n");
|
||||
if (b == 1 && d == 10) {
|
||||
print("STRIKE!!!!!\n");
|
||||
q = 3;
|
||||
}
|
||||
if (b == 2 && d == 10) {
|
||||
print("SPARE!!!!\n");
|
||||
q = 2;
|
||||
}
|
||||
if (b == 2 && d < 10) {
|
||||
print("ERROR!!!\n");
|
||||
q = 1;
|
||||
}
|
||||
if (b == 1 && d < 10) {
|
||||
print("ROLL YOUR 2ND BALL\n");
|
||||
}
|
||||
// Storage of the scores
|
||||
print("\n");
|
||||
a[f * p][b] = d;
|
||||
if (b != 2) {
|
||||
b = 2;
|
||||
m = d;
|
||||
if (q == 3) {
|
||||
a[f * p][b] = d;
|
||||
} else {
|
||||
a[f * p][b] = d - m;
|
||||
if (q == 0) // ROLL
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
a[f * p][3] = q;
|
||||
}
|
||||
} while (++f < 11) ;
|
||||
print("FRAMES\n");
|
||||
for (i = 1; i <= 10; i++)
|
||||
print(" " + i + " ");
|
||||
print("\n");
|
||||
for (p = 1; p <= r; p++) {
|
||||
for (i = 1; i <= 3; i++) {
|
||||
for (j = 1; j <= 10; j++) {
|
||||
print(" " + a[j * p][i] + " ");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
print("DO YOU WANT ANOTHER GAME");
|
||||
str = await input();
|
||||
if (str.substr(0, 1) != "Y")
|
||||
break;
|
||||
// Bug in original game, jumps to 2610, without restarting P variable
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
9
15 Boxing/javascript/boxing.html
Normal file
9
15 Boxing/javascript/boxing.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>BOXING</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="boxing.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
212
15 Boxing/javascript/boxing.js
Normal file
212
15 Boxing/javascript/boxing.js
Normal file
@@ -0,0 +1,212 @@
|
||||
// BOWLING
|
||||
//
|
||||
// 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) + "BOXING\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("BOXING OLYMPIC STYLE (3 ROUNDS -- 2 OUT OF 3 WINS)\n");
|
||||
j = 0;
|
||||
l = 0;
|
||||
print("\n");
|
||||
print("WHAT IS YOUR OPPONENT'S NAME");
|
||||
js = await input();
|
||||
print("INPUT YOUR MAN'S NAME");
|
||||
ls = await input();
|
||||
print("DIFFERENT PUNCHES ARE: (1) FULL SWING; (2) HOOK; (3) UPPERCUT; (4) JAB.\n");
|
||||
print("WHAT IS YOUR MANS BEST");
|
||||
b = parseInt(await input());
|
||||
print("WHAT IS HIS VULNERABILITY");
|
||||
d = parseInt(await input());
|
||||
do {
|
||||
b1 = Math.floor(4 * Math.random() + 1);
|
||||
d1 = Math.floor(4 * Math.random() + 1);
|
||||
} while (b1 == d1) ;
|
||||
print(js + "'S ADVANTAGE IS " + b1 + " AND VULNERABILITY IS SECRET.\n");
|
||||
print("\n");
|
||||
knocked = 0;
|
||||
for (r = 1; r <= 3; r++) {
|
||||
if (j >= 2)
|
||||
break;
|
||||
if (l >= 2)
|
||||
break;
|
||||
x = 0;
|
||||
y = 0;
|
||||
print("ROUND " + r + " BEGIN...\n");
|
||||
for (r1 = 1; r1 <= 7; r1++) {
|
||||
i = Math.floor(10 * Math.random() + 1);
|
||||
if (i <= 5) {
|
||||
print(ls + "'S PUNCH");
|
||||
p = parseInt(await input());
|
||||
if (p == b)
|
||||
x += 2;
|
||||
if (p == 1) {
|
||||
print(ls + " SWINGS AND ");
|
||||
x3 = Math.floor(30 * Math.random() + 1);
|
||||
if (d1 == 4 || x3 < 10) {
|
||||
print("HE CONNECTS!\n");
|
||||
if (x > 35) {
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
x += 15;
|
||||
} else {
|
||||
print("HE MISSES \n");
|
||||
if (x != 1)
|
||||
print("\n\n");
|
||||
}
|
||||
} else if (p == 2) {
|
||||
print(ls + " GIVES THE HOOK... ");
|
||||
h1 = Math.floor(2 * Math.random() + 1);
|
||||
if (d1 == 2) {
|
||||
x += 7;
|
||||
} else if (h1 != 1) {
|
||||
print("CONNECTS...\n");
|
||||
x += 7;
|
||||
} else {
|
||||
print("BUT IT'S BLOCKED!!!!!!!!!!!!!\n");
|
||||
}
|
||||
} else if (p == 3) {
|
||||
print(ls + " TRIES AN UPPERCUT ");
|
||||
d5 = Math.floor(100 * Math.random() + 1);
|
||||
if (d1 == 3 || d5 < 51) {
|
||||
print("AND HE CONNECTS!\n");
|
||||
x += 4;
|
||||
} else {
|
||||
print("AND IT'S BLOCKED (LUCKY BLOCK!)\n");
|
||||
}
|
||||
} else {
|
||||
print(ls + " JABS AT " + js + "'S HEAD ");
|
||||
c = Math.floor(8 * Math.random() + 1);
|
||||
if (d1 == 4 || c >= 4) {
|
||||
x += 3;
|
||||
} else {
|
||||
print("IT'S BLOCKED.\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
j7 = Math.random(4 * Math.random() + 1);
|
||||
if (j7 == b1)
|
||||
y += 2;
|
||||
if (j7 == 1) {
|
||||
print(js + " TAKES A FULL SWING AND");
|
||||
r6 = Math.floor(60 * Math.random() + 1);
|
||||
if (d == 1 || r6 < 30) {
|
||||
print(" POW!!!!! HE HITS HIM RIGHT IN THE FACE!\n");
|
||||
if (y > 35) {
|
||||
knocked = 1;
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
y += 15;
|
||||
} else {
|
||||
print(" IT'S BLOCKED!\n");
|
||||
}
|
||||
} else if (j7 == 2 || j7 == 3) {
|
||||
if (j7 == 2) {
|
||||
print(js + " GETS " + ls + " IN THE JAW (OUCH!)\n");
|
||||
y += 7;
|
||||
print("....AND AGAIN!\n");
|
||||
y += 5;
|
||||
if (y > 35) {
|
||||
knocked = 1;
|
||||
r = 3;
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
// From original, it goes over from handling 2 to handling 3
|
||||
}
|
||||
print(ls + " IS ATTACKED BY AN UPPERCUT (OH,OH)...\n");
|
||||
q4 = Math.floor(200 * Math.random() + 1);
|
||||
if (d == 3 || q4 <= 75) {
|
||||
print("AND " + js + " CONNECTS...\n");
|
||||
y += 8;
|
||||
} else {
|
||||
print(" BLOCKS AND HITS " + js + " WITH A HOOK.\n");
|
||||
x += 5;
|
||||
}
|
||||
} else {
|
||||
print(js + " JABS AND ");
|
||||
z4 = Math.floor(7 * Math.random() + 1);
|
||||
if (d == 4)
|
||||
y += 5;
|
||||
else if (z4 > 4) {
|
||||
print(" BLOOD SPILLS !!!\n");
|
||||
y += 5;
|
||||
} else {
|
||||
print("IT'S BLOCKED!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x > y) {
|
||||
print("\n");
|
||||
print(ls + " WINS ROUND " + r + "\n");
|
||||
l++;
|
||||
} else {
|
||||
print("\n");
|
||||
print(js + " WINS ROUND " + r + "\n");
|
||||
j++;
|
||||
}
|
||||
}
|
||||
if (j >= 2) {
|
||||
print(js + " WINS (NICE GOING, " + js + ").\n");
|
||||
} else if (l >= 2) {
|
||||
print(ls + " AMAZINGLY WINS!!\n");
|
||||
} else if (knocked) {
|
||||
print(ls + " IS KNOCKED COLD AND " + js + " IS THE WINNER AND CHAMP!\n");
|
||||
} else {
|
||||
print(js + " IS KNOCKED COLD AND " + ls + " IS THE WINNER AND CHAMP!\n");
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("AND NOW GOODBYE FROM THE OLYMPIC ARENA.\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
main();
|
||||
9
16 Bug/javascript/bug.html
Normal file
9
16 Bug/javascript/bug.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>BUG</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="bug.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
347
16 Bug/javascript/bug.js
Normal file
347
16 Bug/javascript/bug.js
Normal file
@@ -0,0 +1,347 @@
|
||||
// BUG
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
function draw_head()
|
||||
{
|
||||
print(" HHHHHHH\n");
|
||||
print(" H H\n");
|
||||
print(" H O O H\n");
|
||||
print(" H H\n");
|
||||
print(" H V H\n");
|
||||
print(" HHHHHHH\n");
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(34) + "BUG\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
a = 0;
|
||||
b = 0;
|
||||
h = 0;
|
||||
l = 0;
|
||||
n = 0;
|
||||
p = 0;
|
||||
q = 0;
|
||||
r = 0;
|
||||
s = 0;
|
||||
t = 0;
|
||||
u = 0;
|
||||
v = 0;
|
||||
y = 0;
|
||||
print("THE GAME BUG\n");
|
||||
print("I HOPE YOU ENJOY THIS GAME.\n");
|
||||
print("\n");
|
||||
print("DO YOU WANT INSTRUCTIONS");
|
||||
str = await input();
|
||||
if (str != "NO") {
|
||||
print("THE OBJECT OF BUG IS TO FINISH YOUR BUG BEFORE I FINISH\n");
|
||||
print("MINE. EACH NUMBER STANDS FOR A PART OF THE BUG BODY.\n");
|
||||
print("I WILL ROLL THE DIE FOR YOU, TELL YOU WHAT I ROLLED FOR YOU\n");
|
||||
print("WHAT THE NUMBER STANDS FOR, AND IF YOU CAN GET THE PART.\n");
|
||||
print("IF YOU CAN GET THE PART I WILL GIVE IT TO YOU.\n");
|
||||
print("THE SAME WILL HAPPEN ON MY TURN.\n");
|
||||
print("IF THERE IS A CHANGE IN EITHER BUG I WILL GIVE YOU THE\n");
|
||||
print("OPTION OF SEEING THE PICTURES OF THE BUGS.\n");
|
||||
print("THE NUMBERS STAND FOR PARTS AS FOLLOWS:\n");
|
||||
print("NUMBER\tPART\tNUMBER OF PART NEEDED\n");
|
||||
print("1\tBODY\t1\n");
|
||||
print("2\tNECK\t1\n");
|
||||
print("3\tHEAD\t1\n");
|
||||
print("4\tFEELERS\t2\n");
|
||||
print("5\tTAIL\t1\n");
|
||||
print("6\tLEGS\t6\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
}
|
||||
while (y == 0) {
|
||||
z = Math.floor(6 * Math.random() + 1);
|
||||
c = 1;
|
||||
print("YOU ROLLED A " + z + "\n");
|
||||
switch (z) {
|
||||
case 1:
|
||||
print("1=BODY\n");
|
||||
if (b == 0) {
|
||||
print("YOU NOW HAVE A BODY.\n");
|
||||
b = 1;
|
||||
c = 0;
|
||||
} else {
|
||||
print("YOU DO NOT NEED A BODY.\n");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
print("2=NECK\n");
|
||||
if (n == 0) {
|
||||
if (b == 0) {
|
||||
print("YOU DO NOT HAVE A BODY.\n");
|
||||
} else {
|
||||
print("YOU NOW HAVE A NECK.\n");
|
||||
n = 1;
|
||||
c = 0;
|
||||
}
|
||||
} else {
|
||||
print("YOU DO NOT NEED A NECK.\n");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
print("3=HEAD\n");
|
||||
if (n == 0) {
|
||||
print("YOU DO NOT HAVE A NECK.\n");
|
||||
} else if (h == 0) {
|
||||
print("YOU NEEDED A HEAD.\n");
|
||||
h = 1;
|
||||
c = 0;
|
||||
} else {
|
||||
print("YOU HAVE A HEAD.\n");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
print("4=FEELERS\n");
|
||||
if (h == 0) {
|
||||
print("YOU DO NOT HAVE A HEAD.\n");
|
||||
} else if (a == 2) {
|
||||
print("YOU HAVE TWO FEELERS ALREADY.\n");
|
||||
} else {
|
||||
print("I NOW GIVE YOU A FEELER.\n");
|
||||
a++;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
print("5=TAIL\n");
|
||||
if (b == 0) {
|
||||
print("YOU DO NOT HAVE A BODY.\n");
|
||||
} else if (t == 1) {
|
||||
print("YOU ALREADY HAVE A TAIL.\n");
|
||||
} else {
|
||||
print("I NOW GIVE YOU A TAIL.\n");
|
||||
t++;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
print("6=LEG\n");
|
||||
if (l == 6) {
|
||||
print("YOU HAVE 6 FEET ALREADY.\n");
|
||||
} else if (b == 0) {
|
||||
print("YOU DO NOT HAVE A BODY.\n");
|
||||
} else {
|
||||
l++;
|
||||
c = 0;
|
||||
print("YOU NOW HAVE " + l + " LEGS.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
x = Math.floor(6 * Math.random() + 1) ;
|
||||
print("\n");
|
||||
date = new Date().valueOf;
|
||||
while (date - new Date().valueOf < 1000000) ;
|
||||
print("I ROLLED A " + x + "\n");
|
||||
switch (x) {
|
||||
case 1:
|
||||
print("1=BODY\n");
|
||||
if (p == 1) {
|
||||
print("I DO NOT NEED A BODY.\n");
|
||||
} else {
|
||||
print("I NOW HAVE A BODY.\n");
|
||||
c = 0;
|
||||
p = 1;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
print("2=NECK\n");
|
||||
if (q == 1) {
|
||||
print("I DO NOT NEED A NECK.\n");
|
||||
} else if (p == 0) {
|
||||
print("I DO NOT HAVE A BODY.\n");
|
||||
} else {
|
||||
print("I NOW HAVE A NECK.\n");
|
||||
q = 1;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
print("3=HEAD\n");
|
||||
if (q == 0) {
|
||||
print("I DO NOT HAVE A NECK.\n");
|
||||
} else if (r == 1) {
|
||||
print("I DO NOT NEED A HEAD.\n");
|
||||
} else {
|
||||
print("I NEEDED A HEAD.\n");
|
||||
r = 1;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
print("4=FEELERS\n");
|
||||
if (r == 0) {
|
||||
print("I DO NOT HAVE A HEAD.\n");
|
||||
} else if (s == 2) {
|
||||
print("I HAVE 2 FEELERS ALREADY.\n");
|
||||
} else {
|
||||
print("I GET A FEELER.\n");
|
||||
s++;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
print("5=TAIL\n");
|
||||
if (p == 0) {
|
||||
print("I DO NOT HAVE A BODY.\n");
|
||||
} else if (u == 1) {
|
||||
print("I DO NOT NEED A TAIL.\n");
|
||||
} else {
|
||||
print("I NOW HAVE A TAIL.\n");
|
||||
u = 1;
|
||||
c = 0;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
print("6=LEGS\n");
|
||||
if (v == 6) {
|
||||
print("I HAVE 6 FEET.\n");
|
||||
} else if (p == 0) {
|
||||
print("I DO NOT HAVE A BODY.\n");
|
||||
} else {
|
||||
v++;
|
||||
c = 0;
|
||||
print("I NOW HAVE " + v + " LEGS.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (a == 2 && t == 1 && l == 6) {
|
||||
print("YOUR BUG IS FINISHED.\n");
|
||||
y++;
|
||||
}
|
||||
if (s == 2 && p == 1 && v == 6) {
|
||||
print("MY BUG IS FINISHED.\n");
|
||||
y += 2;
|
||||
}
|
||||
if (c == 1)
|
||||
continue;
|
||||
print("DO YOU WANT THE PICTURES");
|
||||
str = await input();
|
||||
if (str == "NO")
|
||||
continue;
|
||||
print("*****YOUR BUG*****\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
if (a != 0) {
|
||||
for (z = 1; z <= 4; z++) {
|
||||
print(tab(10));
|
||||
for (x = 1; x <= a; x++) {
|
||||
print("A ");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
if (h != 0)
|
||||
draw_head();
|
||||
if (n != 0) {
|
||||
for (z = 1; z <= 2; z++)
|
||||
print(" N N\n");
|
||||
}
|
||||
if (b != 0) {
|
||||
print(" BBBBBBBBBBBB\n");
|
||||
for (z = 1; z <= 2; z++)
|
||||
print(" B B\n");
|
||||
if (t == 1)
|
||||
print("TTTTTB B\n");
|
||||
print(" BBBBBBBBBBBB\n");
|
||||
}
|
||||
if (l != 0) {
|
||||
for (z = 1; z <= 2; z++) {
|
||||
print(tab(5));
|
||||
for (x = 1; x <= l; x++)
|
||||
print(" L");
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
for (z = 1; z <= 4; z++)
|
||||
print("\n");
|
||||
print("*****MY BUG*****\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
if (s != 0) {
|
||||
for (z = 1; z <= 4; z++) {
|
||||
print(tab(10));
|
||||
for (x = 1; x <= s; x++) {
|
||||
print("F ");
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
if (r != 0)
|
||||
draw_head();
|
||||
if (q != 0) {
|
||||
for (z = 1; z <= 2; z++)
|
||||
print(" N N\n");
|
||||
}
|
||||
if (p != 0) {
|
||||
print(" BBBBBBBBBBBB\n");
|
||||
for (z = 1; z <= 2; z++)
|
||||
print(" B B\n");
|
||||
if (u == 1)
|
||||
print("TTTTTB B\n");
|
||||
print(" BBBBBBBBBBBB\n");
|
||||
}
|
||||
if (v != 0) {
|
||||
for (z = 1; z <= 2; z++) {
|
||||
print(tab(5));
|
||||
for (x = 1; x <= v; x++)
|
||||
print(" L");
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
for (z = 1; z <= 4; z++)
|
||||
print("\n");
|
||||
}
|
||||
print("I HOPE YOU ENJOYED THE GAME, PLAY IT AGAIN SOON!!\n");
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -21,7 +21,7 @@
|
||||
330 PRINT
|
||||
340 PRINT "THE CROWD WILL DETERMINE WHAT AWARD YOU DESERVE"
|
||||
350 PRINT "(POSTHUMOUSLY IF NECESSARY)."
|
||||
360 PRINT "THE BRAVER YOU ARE, THE BETTER THE AWARD YOU RECIEVE."
|
||||
360 PRINT "THE BRAVER YOU ARE, THE BETTER THE AWARD YOU RECEIVE."
|
||||
370 PRINT
|
||||
380 PRINT "THE BETTER THE JOB THE PICADORES AND TOREADORES DO,"
|
||||
390 PRINT "THE BETTER YOUR CHANCES ARE."
|
||||
@@ -112,7 +112,7 @@
|
||||
1190 PRINT "YOU PANICKED. THE BULL GORED YOU."
|
||||
1220 GOTO 970
|
||||
1230 K=(6-A)*10*RND(1)/((D(1)+D(2))*5*D(3))
|
||||
1240 IF J=4 THEN 1290
|
||||
1240 IF H=4 THEN 1290
|
||||
1250 IF K>.2 THEN 960
|
||||
1260 PRINT "YOU KILLED THE BULL!"
|
||||
1270 D(5)=2
|
||||
@@ -125,7 +125,7 @@
|
||||
1340 IF D(4)<>0 THEN 1390
|
||||
1350 PRINT "THE CROWD BOOS FOR TEN MINUTES. IF YOU EVER DARE TO SHOW"
|
||||
1360 PRINT "YOUR FACE IN A RING AGAIN, THEY SWEAR THEY WILL KILL YOU--"
|
||||
1370 PRINT "UNLES THE BULL DOES FIRST."
|
||||
1370 PRINT "UNLESS THE BULL DOES FIRST."
|
||||
1380 GOTO 1580
|
||||
1390 DEF FNC(Q)=FND(Q)*RND(1)
|
||||
1395 DEF FND(Q)=(4.5+L/6-(D(1)+D(2))*2.5+4*D(4)+2*D(5)-D(3)^2/120-A)
|
||||
|
||||
9
17 Bullfight/javascript/bullfight.html
Normal file
9
17 Bullfight/javascript/bullfight.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>BULLFIGHT</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="bullfight.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
315
17 Bullfight/javascript/bullfight.js
Normal file
315
17 Bullfight/javascript/bullfight.js
Normal file
@@ -0,0 +1,315 @@
|
||||
// BULLFIGHT
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
var l;
|
||||
var t;
|
||||
var as;
|
||||
var bs;
|
||||
var d = [];
|
||||
var ls = [, "SUPERB", "GOOD", "FAIR", "POOR", "AWFUL"];
|
||||
|
||||
function af(k)
|
||||
{
|
||||
return Math.floor(Math.random() * 2 + 1);
|
||||
}
|
||||
|
||||
function cf(q)
|
||||
{
|
||||
return df(q) * Math.random();
|
||||
}
|
||||
|
||||
function df(q)
|
||||
{
|
||||
return (4.5 + l / 6 - (d[1] + d[2]) * 2.5 + 4 * d[4] + 2 * d[5] - Math.pow(d[3], 2) / 120 - a);
|
||||
}
|
||||
|
||||
function setup_helpers()
|
||||
{
|
||||
b = 3 / a * Math.random();
|
||||
if (b < 0.37)
|
||||
c = 0.5;
|
||||
else if (b < 0.5)
|
||||
c = 0.4;
|
||||
else if (b < 0.63)
|
||||
c = 0.3;
|
||||
else if (b < 0.87)
|
||||
c = 0.2;
|
||||
else
|
||||
c = 0.1;
|
||||
t = Math.floor(10 * c + 0.2);
|
||||
print("THE " + as + bs + " DID A " + ls[t] + " JOB.\n");
|
||||
if (4 <= t) {
|
||||
if (5 != t) {
|
||||
// Lines 1800 and 1810 of original program are unreachable
|
||||
switch (af(0)) {
|
||||
case 1:
|
||||
print("ONE OF THE " + as + bs + " WAS KILLED.\n");
|
||||
break;
|
||||
case 2:
|
||||
print("NO " + as + b + " WERE KILLED.\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (as != "TOREAD")
|
||||
print(af(0) + " OF THE HORSES OF THE " + as + bs + " KILLED.\n");
|
||||
print(af(0) + " OF THE " + as + bs + " KILLED.\n");
|
||||
}
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(34) + "BULL\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
l = 1;
|
||||
print("DO YOU WANT INSTRUCTIONS");
|
||||
str = await input();
|
||||
if (str != "NO") {
|
||||
print("HELLO, ALL YOU BLOODLOVERS AND AFICIONADOS.\n");
|
||||
print("HERE IS YOUR BIG CHANCE TO KILL A BULL.\n");
|
||||
print("\n");
|
||||
print("ON EACH PASS OF THE BULL, YOU MAY TRY\n");
|
||||
print("0 - VERONICA (DANGEROUS INSIDE MOVE OF THE CAPE)\n");
|
||||
print("1 - LESS DANGEROUS OUTSIDE MOVE OF THE CAPE\n");
|
||||
print("2 - ORDINARY SWIRL OF THE CAPE.\n");
|
||||
print("\n");
|
||||
print("INSTEAD OF THE ABOVE, YOU MAY TRY TO KILL THE BULL\n");
|
||||
print("ON ANY TURN: 4 (OVER THE HORNS), 5 (IN THE CHEST).\n");
|
||||
print("BUT IF I WERE YOU,\n");
|
||||
print("I WOULDN'T TRY IT BEFORE THE SEVENTH PASS.\n");
|
||||
print("\n");
|
||||
print("THE CROWD WILL DETERMINE WHAT AWARD YOU DESERVE\n");
|
||||
print("(POSTHUMOUSLY IF NECESSARY).\n");
|
||||
print("THE BRAVER YOU ARE, THE BETTER THE AWARD YOU RECEIVE.\n");
|
||||
print("\n");
|
||||
print("THE BETTER THE JOB THE PICADORES AND TOREADORES DO,\n");
|
||||
print("THE BETTER YOUR CHANCES ARE.\n");
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
d[5] = 1;
|
||||
d[4] = 1;
|
||||
d[3] = 0;
|
||||
a = Math.floor(Math.random() * 5 + 1);
|
||||
print("YOU HAVE DRAWN A " + ls[a] + " BULL.\n");
|
||||
if (a > 4) {
|
||||
print("YOU'RE LUCKY.\n");
|
||||
} else if (a < 2) {
|
||||
print("GOOD LUCK. YOU'LL NEED IT.\n");
|
||||
print("\n");
|
||||
}
|
||||
print("\n");
|
||||
as = "PICADO";
|
||||
bs = "RES";
|
||||
setup_helpers();
|
||||
d[1] = c;
|
||||
as = "TOREAD";
|
||||
bs = "ORES";
|
||||
setup_helpers();
|
||||
d[2] = c;
|
||||
print("\n");
|
||||
print("\n");
|
||||
z = 0;
|
||||
while (z == 0) {
|
||||
d[3]++;
|
||||
print("PASS NUMBER " + d[3] + "\n");
|
||||
if (d[3] >= 3) {
|
||||
print("HERE COMES THE BULL. TRY FOR A KILL");
|
||||
while (1) {
|
||||
str = await input();
|
||||
if (str != "YES" && str != "NO")
|
||||
print("INCORRECT ANSWER - - PLEASE TYPE 'YES' OR 'NO'.\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
z1 = (str == "YES") ? 1 : 2;
|
||||
if (z1 != 1) {
|
||||
print("CAPE MOVE");
|
||||
}
|
||||
} else {
|
||||
print("THE BULL IS CHARGING AT YOU! YOU ARE THE MATADOR--\n");
|
||||
print("DO YOU WANT TO KILL THE BULL");
|
||||
while (1) {
|
||||
str = await input();
|
||||
if (str != "YES" && str != "NO")
|
||||
print("INCORRECT ANSWER - - PLEASE TYPE 'YES' OR 'NO'.\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
z1 = (str == "YES") ? 1 : 2;
|
||||
if (z1 != 1) {
|
||||
print("WHAT MOVE DO YOU MAKE WITH THE CAPE");
|
||||
}
|
||||
}
|
||||
gore = 0;
|
||||
if (z1 != 1) {
|
||||
while (1) {
|
||||
e = parseInt(await input());
|
||||
if (e >= 3) {
|
||||
print("DON'T PANIC, YOU IDIOT! PUT DOWN A CORRECT NUMBER\n");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (e == 0)
|
||||
m = 3;
|
||||
else if (e == 1)
|
||||
m = 2;
|
||||
else
|
||||
m = 0.5;
|
||||
l += m;
|
||||
f = (6 - a + m / 10) * Math.random() / ((d[1] + d[2] + d[3] / 10) * 5);
|
||||
if (f < 0.51)
|
||||
continue;
|
||||
gore = 1;
|
||||
} else {
|
||||
z = 1;
|
||||
print("\n");
|
||||
print("IT IS THE MOMENT OF THE TRUTH.\n");
|
||||
print("\n");
|
||||
print("HOW DO YOU TRY TO KILL THE BULL");
|
||||
h = parseInt(await input());
|
||||
if (h != 4 && h != 5) {
|
||||
print("YOU PANICKED. THE BULL GORED YOU.\n");
|
||||
gore = 2;
|
||||
} else {
|
||||
k = (6 - a) * 10 * Math.random() / ((d[1] + d[2]) * 5 * d[3]);
|
||||
if (h != 4) { // Bug in original game, it says J instead of H
|
||||
if (k > 0.2)
|
||||
gore = 1;
|
||||
} else {
|
||||
if (k > 0.8)
|
||||
gore = 1;
|
||||
}
|
||||
if (gore == 0) {
|
||||
print("YOU KILLED THE BULL!\n");
|
||||
d[5] = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gore) {
|
||||
if (gore == 1)
|
||||
print("THE BULL HAS GORED YOU!\n");
|
||||
kill = false;
|
||||
while (1) {
|
||||
if (af(0) == 1) {
|
||||
print("YOU ARE DEAD.\n");
|
||||
d[4] = 1.5;
|
||||
kill = true;
|
||||
break;
|
||||
}
|
||||
print("YOU ARE STILL ALIVE.\n");
|
||||
print("\n");
|
||||
print("DO YOU RUN FROM THE RING");
|
||||
while (1) {
|
||||
str = await input();
|
||||
if (str != "YES" && str != "NO")
|
||||
print("INCORRECT ANSWER - - PLEASE TYPE 'YES' OR 'NO'.\n");
|
||||
else
|
||||
break;
|
||||
}
|
||||
z1 = (str == "YES") ? 1 : 2;
|
||||
if (z1 != 2) {
|
||||
print("COWARD\n");
|
||||
d[4] = 0;
|
||||
kill = true;
|
||||
break;
|
||||
}
|
||||
print("YOU ARE BRAVE. STUPID, BUT BRAVE.\n");
|
||||
if (af(0) == 1) {
|
||||
d[4] = 2;
|
||||
kill = false;
|
||||
break;
|
||||
}
|
||||
print("YOU ARE GORED AGAIN!\n");
|
||||
}
|
||||
if (kill)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
if (d[4] == 0) {
|
||||
print("THE CROWD BOOS FOR TEN MINUTES. IF YOU EVER DARE TO SHOW\n");
|
||||
print("YOUR FACE IN A RING AGAIN, THEY SWEAR THEY WILL KILL YOU--\n");
|
||||
print("UNLESS THE BULL DOES FIRST.\n");
|
||||
} else {
|
||||
if (d[4] == 2) {
|
||||
print("THE CROWD CHEERS WILDLY!\n");
|
||||
} else if (d[5] == 2) {
|
||||
print("THE CROWD CHEERS!\n");
|
||||
print("\n");
|
||||
}
|
||||
print("THE CROWD AWARDS YOU\n");
|
||||
if (cf(0) < 2.4) {
|
||||
print("NOTHING AT ALL.\n");
|
||||
} else if (cf(0) < 4.9) {
|
||||
print("ONE EAR OF THE BULL.\n");
|
||||
} else if (cf(0) < 7.4) {
|
||||
print("BOTH EARS OF THE BULL!\n");
|
||||
print("OLE!\n");
|
||||
} else {
|
||||
print("OLE! YOU ARE 'MUY HOMBRE'!! OLE! OLE!\n");
|
||||
}
|
||||
print("\n");
|
||||
print("ADIOS\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
9
70 Poetry/javascript/poetry.html
Normal file
9
70 Poetry/javascript/poetry.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>POETRY</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="poetry.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
173
70 Poetry/javascript/poetry.js
Normal file
173
70 Poetry/javascript/poetry.js
Normal file
@@ -0,0 +1,173 @@
|
||||
// POETRY
|
||||
//
|
||||
// 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(30) + "POETRY\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
|
||||
times = 0;
|
||||
|
||||
i = 1;
|
||||
j = 1;
|
||||
k = 0;
|
||||
u = 0;
|
||||
while (1) {
|
||||
if (j == 1) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
print("MIDNIGHT DREARY");
|
||||
break;
|
||||
case 2:
|
||||
print("FIERY EYES");
|
||||
break;
|
||||
case 3:
|
||||
print("BIRD OF FIEND");
|
||||
break;
|
||||
case 4:
|
||||
print("THING OF EVIL");
|
||||
break;
|
||||
case 5:
|
||||
print("PROPHET");
|
||||
break;
|
||||
}
|
||||
} else if (j == 2) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
print("BEGUILING ME");
|
||||
u = 2;
|
||||
break;
|
||||
case 2:
|
||||
print("THRILLED ME");
|
||||
break;
|
||||
case 3:
|
||||
print("STILL SITTING....");
|
||||
u = 0;
|
||||
break;
|
||||
case 4:
|
||||
print("NEVER FLITTING");
|
||||
u = 2;
|
||||
break;
|
||||
case 5:
|
||||
print("BURNED");
|
||||
break;
|
||||
}
|
||||
} else if (j == 3) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
print("AND MY SOUL");
|
||||
break;
|
||||
case 2:
|
||||
print("DARKNESS THERE");
|
||||
break;
|
||||
case 3:
|
||||
print("SHALL BE LIFTED");
|
||||
break;
|
||||
case 4:
|
||||
print("QUOTH THE RAVEN");
|
||||
break;
|
||||
case 5:
|
||||
if (u == 0)
|
||||
break;
|
||||
print("SIGN OF PARTING");
|
||||
break;
|
||||
}
|
||||
} else if (j == 4) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
print("NOTHING MORE");
|
||||
break;
|
||||
case 2:
|
||||
print("YET AGAIN");
|
||||
break;
|
||||
case 3:
|
||||
print("SLOWLY CREEPING");
|
||||
break;
|
||||
case 4:
|
||||
print("...EVERMORE");
|
||||
break;
|
||||
case 5:
|
||||
print("NEVERMORE");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (u != 0 && Math.random() <= 0.19) {
|
||||
print(",");
|
||||
u = 2;
|
||||
}
|
||||
if (Math.random() <= 0.65) {
|
||||
print(" ");
|
||||
u++;
|
||||
} else {
|
||||
print("\n");
|
||||
u = 0;
|
||||
}
|
||||
while (1) {
|
||||
i = Math.floor(Math.floor(10 * Math.random()) / 2) + 1;
|
||||
j++;
|
||||
k++;
|
||||
if (u == 0 && j % 2 == 0)
|
||||
print(" ");
|
||||
if (j != 5)
|
||||
break;
|
||||
j = 0;
|
||||
print("\n");
|
||||
if (k <= 20)
|
||||
continue;
|
||||
print("\n");
|
||||
u = 0;
|
||||
k = 0;
|
||||
j = 2;
|
||||
break;
|
||||
}
|
||||
if (u == 0 && k == 0 && j == 2 && ++times == 10)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
9
73 Reverse/javascript/reverse.html
Normal file
9
73 Reverse/javascript/reverse.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>REVERSE</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="reverse.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
159
73 Reverse/javascript/reverse.js
Normal file
159
73 Reverse/javascript/reverse.js
Normal file
@@ -0,0 +1,159 @@
|
||||
// REVERSE
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
var a = [];
|
||||
var n;
|
||||
|
||||
// Subroutine to print the rules
|
||||
function print_rules()
|
||||
{
|
||||
print("\n");
|
||||
print("THIS IS THE GAME OF 'REVERSE'. TO WIN, ALL YOU HAVE\n");
|
||||
print("TO DO IS ARRANGE A LIST OF NUMBERS (1 THROUGH " + n + ")\n");
|
||||
print("IN NUMERICAL ORDER FROM LEFT TO RIGHT. TO MOVE, YOU\n");
|
||||
print("TELL ME HOW MANY NUMBERS (COUNTING FROM THE LEFT) TO\n");
|
||||
print("REVERSE. FOR EXAMPLE, IF THE CURRENT LIST IS:\n");
|
||||
print("\n");
|
||||
print("2 3 4 5 1 6 7 8 9\n");
|
||||
print("\n");
|
||||
print("AND YOU REVERSE 4, THE RESULT WILL BE:\n");
|
||||
print("\n");
|
||||
print("5 4 3 2 1 6 7 8 9\n");
|
||||
print("\n");
|
||||
print("NOW IF YOU REVERSE 5, YOU WIN!\n");
|
||||
print("\n");
|
||||
print("1 2 3 4 5 6 7 8 9\n");
|
||||
print("\n");
|
||||
print("NO DOUBT YOU WILL LIKE THIS GAME, BUT\n");
|
||||
print("IF YOU WANT TO QUIT, REVERSE 0 (ZERO).\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
// Subroutine to print list
|
||||
function print_list()
|
||||
{
|
||||
print("\n");
|
||||
for (k = 1; k <= n; k++)
|
||||
print(" " + a[k] + " ");
|
||||
print("\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(32) + "REVERSE\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("REVERSE -- A GAME OF SKILL\n");
|
||||
print("\n");
|
||||
for (i = 0; i <= 20; i++)
|
||||
a[i] = 0;
|
||||
// *** N=NUMBER OF NUMBER
|
||||
n = 9;
|
||||
print("DO YOU WANT THE RULES");
|
||||
str = await input();
|
||||
if (str != "NO")
|
||||
print_rules();
|
||||
while (1) {
|
||||
// *** Make a random list a(1) to a(n)
|
||||
a[1] = Math.floor((n - 1) * Math.random() + 2);
|
||||
for (k = 2; k <= n; k++) {
|
||||
do {
|
||||
a[k] = Math.floor(n * Math.random() + 1);
|
||||
for (j = 1; j <= k - 1; j++) {
|
||||
if (a[k] == a[j])
|
||||
break;
|
||||
}
|
||||
} while (j <= k - 1) ;
|
||||
}
|
||||
// *** Print original list and start game
|
||||
print("\n");
|
||||
print("HERE WE GO ... THE LIST IS:\n");
|
||||
t = 0;
|
||||
print_list();
|
||||
while (1) {
|
||||
while (1) {
|
||||
print("HOW MANY SHALL I REVERSE");
|
||||
r = parseInt(await input());
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r <= n)
|
||||
break;
|
||||
print("OOPS! TOO MANY! I CAN REVERSE AT MOST " + n + "\n");
|
||||
}
|
||||
if (r == 0)
|
||||
break;
|
||||
t++;
|
||||
// *** Reverse r numbers and print new list
|
||||
for (k = 1; k <= Math.floor(r / 2); k++) {
|
||||
z = a[k];
|
||||
a[k] = a[r - k + 1];
|
||||
a[r - k + 1] = z;
|
||||
}
|
||||
print_list();
|
||||
// *** Check for a win
|
||||
for (k = 1; k <= n; k++) {
|
||||
if (a[k] != k)
|
||||
break;
|
||||
}
|
||||
if (k > n) {
|
||||
print("YOU WON IT IN " + t + " MOVES!!!\n");
|
||||
print("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
print("\n");
|
||||
print("TRY AGAIN (YES OR NO)");
|
||||
str = await input();
|
||||
if (str != "YES")
|
||||
break;
|
||||
}
|
||||
print("\n");
|
||||
print("O.K. HOPE YOU HAD FUN!!\n");
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user