Ported BOWLING, BOXING and BUG to Javascript

This commit is contained in:
nanochess
2021-02-25 22:16:47 -06:00
parent 88056a5236
commit 528b4d7a4a
6 changed files with 765 additions and 0 deletions

View 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>

View 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();

View 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>

View 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();

View 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
View 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();