mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 17:17:59 -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
37_Football/javascript/README.md
Normal file
3
37_Football/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
37_Football/javascript/football.html
Normal file
9
37_Football/javascript/football.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>FOOTBALL</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="football.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
504
37_Football/javascript/football.js
Normal file
504
37_Football/javascript/football.js
Normal file
@@ -0,0 +1,504 @@
|
||||
// FOOTBALL
|
||||
//
|
||||
// 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 player_data = [17,8,4,14,19,3,10,1,7,11,15,9,5,20,13,18,16,2,12,6,
|
||||
20,2,17,5,8,18,12,11,1,4,19,14,10,7,9,15,6,13,16,3];
|
||||
var aa = [];
|
||||
var ba = [];
|
||||
var ca = [];
|
||||
var ha = [];
|
||||
var ta = [];
|
||||
var wa = [];
|
||||
var xa = [];
|
||||
var ya = [];
|
||||
var za = [];
|
||||
var ms = [];
|
||||
var da = [];
|
||||
var ps = [, "PITCHOUT","TRIPLE REVERSE","DRAW","QB SNEAK","END AROUND",
|
||||
"DOUBLE REVERSE","LEFT SWEEP","RIGHT SWEEP","OFF TACKLE",
|
||||
"WISHBONE OPTION","FLARE PASS","SCREEN PASS",
|
||||
"ROLL OUT OPTION","RIGHT CURL","LEFT CURL","WISHBONE OPTION",
|
||||
"SIDELINE PASS","HALF-BACK OPTION","RAZZLE-DAZZLE","BOMB!!!!"];
|
||||
var p;
|
||||
var t;
|
||||
|
||||
function field_headers()
|
||||
{
|
||||
print("TEAM 1 [0 10 20 30 40 50 60 70 80 90");
|
||||
print(" 100] TEAM 2\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function separator()
|
||||
{
|
||||
str = "";
|
||||
for (x = 1; x <= 72; x++)
|
||||
str += "+";
|
||||
print(str + "\n");
|
||||
}
|
||||
|
||||
function show_ball()
|
||||
{
|
||||
print(tab(da[t] + 5 + p / 2) + ms[t] + "\n");
|
||||
field_headers();
|
||||
}
|
||||
|
||||
function show_scores()
|
||||
{
|
||||
print("\n");
|
||||
print("TEAM 1 SCORE IS " + ha[1] + "\n");
|
||||
print("TEAM 2 SCORE IS " + ha[2] + "\n");
|
||||
print("\n");
|
||||
if (ha[t] >= e) {
|
||||
print("TEAM " + t + " WINS*******************");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function loss_posession() {
|
||||
print("\n");
|
||||
print("** LOSS OF POSSESSION FROM TEAM " + t + " TO TEAM " + ta[t] + "\n");
|
||||
print("\n");
|
||||
separator();
|
||||
print("\n");
|
||||
t = ta[t];
|
||||
}
|
||||
|
||||
function touchdown() {
|
||||
print("\n");
|
||||
print("TOUCHDOWN BY TEAM " + t + " *********************YEA TEAM\n");
|
||||
q = 7;
|
||||
g = Math.random();
|
||||
if (g <= 0.1) {
|
||||
q = 6;
|
||||
print("EXTRA POINT NO GOOD\n");
|
||||
} else {
|
||||
print("EXTRA POINT GOOD\n");
|
||||
}
|
||||
ha[t] = ha[t] + q;
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(32) + "FOOTBALL\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("PRESENTING N.F.U. FOOTBALL (NO FORTRAN USED)\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
while (1) {
|
||||
print("DO YOU WANT INSTRUCTIONS");
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
}
|
||||
if (str == "YES") {
|
||||
print("THIS IS A FOOTBALL GAME FOR TWO TEAMS IN WHICH PLAYERS MUST\n");
|
||||
print("PREPARE A TAPE WITH A DATA STATEMENT (1770 FOR TEAM 1,\n");
|
||||
print( "1780 FOR TEAM 2) IN WHICH EACH TEAM SCRAMBLES NOS. 1-20\n");
|
||||
print("THESE NUMBERS ARE THEN ASSIGNED TO TWENTY GIVEN PLAYS.\n");
|
||||
print("A LIST OF NOS. AND THEIR PLAYS IS PROVIDED WITH\n");
|
||||
print("BOTH TEAMS HAVING THE SAME PLAYS. THE MORE SIMILAR THE\n");
|
||||
print("PLAYS THE LESS YARDAGE GAINED. SCORES ARE GIVEN\n");
|
||||
print("WHENEVER SCORES ARE MADE. SCORES MAY ALSO BE OBTAINED\n");
|
||||
print("BY INPUTTING 99,99 FOR PLAY NOS. TO PUNT OR ATTEMPT A\n");
|
||||
print("FIELD GOAL, INPUT 77,77 FOR PLAY NUMBERS. QUESTIONS WILL BE\n");
|
||||
print("ASKED THEN. ON 4TH DOWN, YOU WILL ALSO BE ASKED WHETHER\n");
|
||||
print("YOU WANT TO PUNT OR ATTEMPT A FIELD GOAL. IF THE ANSWER TO\n");
|
||||
print("BOTH QUESTIONS IS NO IT WILL BE ASSUMED YOU WANT TO\n");
|
||||
print("TRY AND GAIN YARDAGE. ANSWER ALL QUESTIONS YES OR NO.\n");
|
||||
print("THE GAME IS PLAYED UNTIL PLAYERS TERMINATE (CONTROL-C).\n");
|
||||
print("PLEASE PREPARE A TAPE AND RUN.\n");
|
||||
}
|
||||
print("\n");
|
||||
print("PLEASE INPUT SCORE LIMIT ON GAME");
|
||||
e = parseInt(await input());
|
||||
for (i = 1; i <= 40; i++) {
|
||||
if (i <= 20) {
|
||||
aa[player_data[i - 1]] = i;
|
||||
} else {
|
||||
ba[player_data[i - 1]] = i - 20;
|
||||
}
|
||||
ca[i] = player_data[i - 1];
|
||||
}
|
||||
l = 0;
|
||||
t = 1;
|
||||
do {
|
||||
print("TEAM " + t + " PLAY CHART\n");
|
||||
print("NO. PLAY\n");
|
||||
for (i = 1; i <= 20; i++) {
|
||||
str = "" + ca[i + l];
|
||||
while (str.length < 6)
|
||||
str += " ";
|
||||
str += ps[i];
|
||||
print(str + "\n");
|
||||
}
|
||||
l += 20;
|
||||
t = 2;
|
||||
print("\n");
|
||||
print("TEAR OFF HERE----------------------------------------------\n");
|
||||
for (x = 1; x <= 11; x++)
|
||||
print("\n");
|
||||
} while (l == 20) ;
|
||||
da[1] = 0;
|
||||
da[2] = 3;
|
||||
ms[1] = "--->";
|
||||
ms[2] = "<---";
|
||||
ha[1] = 0;
|
||||
ha[2] = 0;
|
||||
ta[1] = 2;
|
||||
ta[2] = 1;
|
||||
wa[1] = -1;
|
||||
wa[2] = 1;
|
||||
xa[1] = 100;
|
||||
xa[2] = 0;
|
||||
ya[1] = 1;
|
||||
ya[2] = -1;
|
||||
za[1] = 0;
|
||||
za[2] = 100;
|
||||
p = 0;
|
||||
field_headers();
|
||||
print("TEAM 1 DEFEND 0 YD GOAL -- TEAM 2 DEFENDS 100 YD GOAL.\n");
|
||||
t = Math.floor(2 * Math.random() + 1);
|
||||
print("\n");
|
||||
print("THE COIN IS FLIPPED\n");
|
||||
routine = 1;
|
||||
while (1) {
|
||||
if (routine <= 1) {
|
||||
p = xa[t] - ya[t] * 40;
|
||||
separator();
|
||||
print("\n");
|
||||
print("TEAM " + t + " RECEIVES KICK-OFF\n");
|
||||
k = Math.floor(26 * Math.random() + 40);
|
||||
}
|
||||
if (routine <= 2) {
|
||||
p = p - ya[t] * k;
|
||||
}
|
||||
if (routine <= 3) {
|
||||
if (wa[t] * p >= za[t] + 10) {
|
||||
print("\n");
|
||||
print("BALL WENT OUT OF ENDZONE --AUTOMATIC TOUCHBACK--\n");
|
||||
p = za[t] - wa[t] * 20;
|
||||
if (routine <= 4)
|
||||
routine = 5;
|
||||
} else {
|
||||
print("BALL WENT " + k + " YARDS. NOW ON " + p + "\n");
|
||||
show_ball();
|
||||
}
|
||||
}
|
||||
if (routine <= 4) {
|
||||
while (1) {
|
||||
print("TEAM " + t + " DO YOU WANT TO RUNBACK");
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
}
|
||||
if (str == "YES") {
|
||||
k = Math.floor(9 * Math.random() + 1);
|
||||
r = Math.floor(((xa[t] - ya[t] * p + 25) * Math.random() - 15) / k);
|
||||
p = p - wa[t] * r;
|
||||
print("\n");
|
||||
print("RUNBACK TEAM " + t + " " + r + " YARDS\n");
|
||||
g = Math.random();
|
||||
if (g < 0.25) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
} else if (ya[t] * p >= xa[t]) {
|
||||
touchdown();
|
||||
if (show_scores())
|
||||
return;
|
||||
t = ta[t];
|
||||
routine = 1;
|
||||
continue;
|
||||
} else if (wa[t] * p >= za[t]) {
|
||||
print("\n");
|
||||
print("SAFETY AGAINST TEAM " + t + " **********************OH-OH\n");
|
||||
ha[ta[t]] = ha[ta[t]] + 2;
|
||||
if (show_scores())
|
||||
return;
|
||||
print("TEAM " + t + " DO YOU WANT TO PUNT INSTEAD OF A KICKOFF");
|
||||
str = await input();
|
||||
p = za[t] - wa[t] * 20;
|
||||
if (str == "YES") {
|
||||
print("\n");
|
||||
print("TEAM " + t + " WILL PUNT\n");
|
||||
g = Math.random();
|
||||
if (g < 0.25) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
}
|
||||
print("\n");
|
||||
separator();
|
||||
k = Math.floor(25 * Math.random() + 35);
|
||||
t = ta[t];
|
||||
routine = 2;
|
||||
continue;
|
||||
}
|
||||
touchdown();
|
||||
if (show_scores())
|
||||
return;
|
||||
t = ta[t];
|
||||
routine = 1;
|
||||
continue;
|
||||
} else {
|
||||
routine = 5;
|
||||
continue;
|
||||
}
|
||||
} else if (str == "NO") {
|
||||
if (wa[t] * p >= za[t])
|
||||
p = za[t] - wa[t] * 20;
|
||||
}
|
||||
}
|
||||
if (routine <= 5) {
|
||||
d = 1;
|
||||
s = p;
|
||||
}
|
||||
if (routine <= 6) {
|
||||
str = "";
|
||||
for (i = 1; i <= 72; i++)
|
||||
str += "=";
|
||||
print(str + "\n");
|
||||
print("TEAM " + t + " DOWN " + d + " ON " + p + "\n");
|
||||
if (d == 1) {
|
||||
if (ya[t] * (p + ya[t] * 10) >= xa[t])
|
||||
c = 8;
|
||||
else
|
||||
c = 4;
|
||||
}
|
||||
if (c != 8) {
|
||||
print(tab(27) + (10 - (ya[t] * p - ya[t] * s)) + " YARDS TO 1ST DOWN\n");
|
||||
} else {
|
||||
print(tab(27) + (xa[t] - ya[t] * p) + " YARDS\n");
|
||||
}
|
||||
show_ball();
|
||||
if (d == 4)
|
||||
routine = 8;
|
||||
}
|
||||
if (routine <= 7) {
|
||||
u = Math.floor(3 * Math.random() - 1);
|
||||
while (1) {
|
||||
print("INPUT OFFENSIVE PLAY, DEFENSIVE PLAY");
|
||||
str = await input();
|
||||
if (t == 1) {
|
||||
p1 = parseInt(str);
|
||||
p2 = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
} else {
|
||||
p2 = parseInt(str);
|
||||
p1 = parseInt(str.substr(str.indexOf(",") + 1));
|
||||
}
|
||||
if (p1 == 99) {
|
||||
if (show_scores())
|
||||
return;
|
||||
if (p1 == 99)
|
||||
continue;
|
||||
}
|
||||
if (p1 < 1 || p1 > 20 || p2 < 1 || p2 > 20) {
|
||||
print("ILLEGAL PLAY NUMBER, CHECK AND\n");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (d == 4 || p1 == 77) {
|
||||
while (1) {
|
||||
print("DOES TEAM " + t + " WANT TO PUNT");
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
}
|
||||
if (str == "YES") {
|
||||
print("\n");
|
||||
print("TEAM " + t + " WILL PUNT\n");
|
||||
g = Math.random();
|
||||
if (g < 0.25) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
}
|
||||
print("\n");
|
||||
separator();
|
||||
k = Math.floor(25 * Math.random() + 35);
|
||||
t = ta[t];
|
||||
routine = 2;
|
||||
continue;
|
||||
}
|
||||
while (1) {
|
||||
print("DOES TEAM " + t + " WANT TO ATTEMPT A FIELD GOAL");
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
}
|
||||
if (str == "YES") {
|
||||
print("\n");
|
||||
print("TEAM " + t + " WILL ATTEMPT A FIELD GOAL\n");
|
||||
g = Math.random();
|
||||
if (g < 0.025) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
} else {
|
||||
f = Math.floor(35 * Math.random() + 20);
|
||||
print("\n");
|
||||
print("KICK IS " + f + " YARDS LONG\n");
|
||||
p = p - wa[t] * f;
|
||||
g = Math.random();
|
||||
if (g < 0.35) {
|
||||
print("BALL WENT WIDE\n");
|
||||
} else if (ya[t] * p >= xa[t]) {
|
||||
print("FIELD GOLD GOOD FOR TEAM " + t + " *********************YEA");
|
||||
q = 3;
|
||||
ha[t] = ha[t] + q;
|
||||
if (show_scores())
|
||||
return;
|
||||
t = ta[t];
|
||||
routine = 1;
|
||||
continue;
|
||||
}
|
||||
print("FIELD GOAL UNSUCCESFUL TEAM " + t + "-----------------TOO BAD\n");
|
||||
print("\n");
|
||||
separator();
|
||||
if (ya[t] * p < xa[t] + 10) {
|
||||
print("\n");
|
||||
print("BALL NOW ON " + p + "\n");
|
||||
t = ta[t];
|
||||
show_ball();
|
||||
routine = 4;
|
||||
continue;
|
||||
} else {
|
||||
t = ta[t];
|
||||
routine = 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
routine = 7;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
y = Math.floor(Math.abs(aa[p1] - ba[p2]) / 19 * ((xa[t] - ya[t] * p + 25) * Math.random() - 15));
|
||||
print("\n");
|
||||
if (t == 1 && aa[p1] < 11 || t == 2 && ba[p2] < 11) {
|
||||
print("THE BALL WAS RUN\n");
|
||||
} else if (u == 0) {
|
||||
print("PASS INCOMPLETE TEAM " + t + "\n");
|
||||
y = 0;
|
||||
} else {
|
||||
g = Math.random();
|
||||
if (g <= 0.025 && y > 2) {
|
||||
print("PASS COMPLETED\n");
|
||||
} else {
|
||||
print("QUARTERBACK SCRAMBLED\n");
|
||||
}
|
||||
}
|
||||
p = p - wa[t] * y;
|
||||
print("\n");
|
||||
print("NET YARDS GAINED ON DOWN " + d + " ARE " + y + "\n");
|
||||
|
||||
g = Math.random();
|
||||
if (g <= 0.025) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
} else if (ya[t] * p >= xa[t]) {
|
||||
touchdown();
|
||||
if (show_scores())
|
||||
return;
|
||||
t = ta[t];
|
||||
routine = 1;
|
||||
continue;
|
||||
} else if (wa[t] * p >= za[t]) {
|
||||
print("\n");
|
||||
print("SAFETY AGAINST TEAM " + t + " **********************OH-OH\n");
|
||||
ha[ta[t]] = ha[ta[t]] + 2;
|
||||
if (show_scores())
|
||||
return;
|
||||
print("TEAM " + t + " DO YOU WANT TO PUNT INSTEAD OF A KICKOFF");
|
||||
str = await input();
|
||||
p = za[t] - wa[t] * 20;
|
||||
if (str == "YES") {
|
||||
print("\n");
|
||||
print("TEAM " + t + " WILL PUNT\n");
|
||||
g = Math.random();
|
||||
if (g < 0.25) {
|
||||
loss_posession();
|
||||
routine = 4;
|
||||
continue;
|
||||
}
|
||||
print("\n");
|
||||
separator();
|
||||
k = Math.floor(25 * Math.random() + 35);
|
||||
t = ta[t];
|
||||
routine = 2;
|
||||
continue;
|
||||
}
|
||||
touchdown();
|
||||
if (show_scores())
|
||||
return;
|
||||
t = ta[t];
|
||||
routine = 1;
|
||||
} else if (ya[t] * p - ya[t] * s >= 10) {
|
||||
routine = 5;
|
||||
} else {
|
||||
d++;
|
||||
if (d != 5) {
|
||||
routine = 6;
|
||||
} else {
|
||||
print("\n");
|
||||
print("CONVERSION UNSUCCESSFUL TEAM " + t + "\n");
|
||||
t = ta[t];
|
||||
print("\n");
|
||||
separator();
|
||||
routine = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
9
37_Football/javascript/ftball.html
Normal file
9
37_Football/javascript/ftball.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>FTBALL</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="ftball.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
508
37_Football/javascript/ftball.js
Normal file
508
37_Football/javascript/ftball.js
Normal file
@@ -0,0 +1,508 @@
|
||||
// FTBALL
|
||||
//
|
||||
// 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 os = [];
|
||||
var sa = [];
|
||||
var ls = [, "KICK","RECEIVE"," YARD ","RUN BACK FOR ","BALL ON ",
|
||||
"YARD LINE"," SIMPLE RUN"," TRICKY RUN"," SHORT PASS",
|
||||
" LONG PASS","PUNT"," QUICK KICK "," PLACE KICK"," LOSS ",
|
||||
" NO GAIN","GAIN "," TOUCHDOWN "," TOUCHBACK ","SAFETY***",
|
||||
"JUNK"];
|
||||
var p;
|
||||
var x;
|
||||
var x1;
|
||||
|
||||
function fnf(x)
|
||||
{
|
||||
return 1 - 2 * p;
|
||||
}
|
||||
|
||||
function fng(z)
|
||||
{
|
||||
return p * (x1 - x) + (1 - p) * (x - x1);
|
||||
}
|
||||
|
||||
function show_score()
|
||||
{
|
||||
print("\n");
|
||||
print("SCORE: " + sa[0] + " TO " + sa[1] + "\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function show_position()
|
||||
{
|
||||
if (x <= 50) {
|
||||
print(ls[5] + os[0] + " " + x + " " + ls[6] + "\n");
|
||||
} else {
|
||||
print(ls[5] + os[1] + " " + (100 - x) + " " + ls[6] + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function offensive_td()
|
||||
{
|
||||
print(ls[17] + "***\n");
|
||||
if (Math.random() <= 0.8) {
|
||||
sa[p] = sa[p] + 7;
|
||||
print("KICK IS GOOD.\n");
|
||||
} else {
|
||||
print("KICK IS OFF TO THE SIDE\n");
|
||||
sa[p] = sa[p] + 6;
|
||||
}
|
||||
show_score();
|
||||
print(os[p] + " KICKS OFF\n");
|
||||
p = 1 - p;
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "FTBALL\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("THIS IS DARTMOUTH CHAMPIONSHIP FOOTBALL.\n");
|
||||
print("\n");
|
||||
print("YOU WILL QUARTERBACK DARTMOUTH. CALL PLAYS AS FOLLOWS:\n");
|
||||
print("1= SIMPLE RUN; 2= TRICKY RUN; 3= SHORT PASS;\n");
|
||||
print("4= LONG PASS; 5= PUNT; 6= QUICK KICK; 7= PLACE KICK.\n");
|
||||
print("\n");
|
||||
print("CHOOSE YOUR OPPONENT");
|
||||
os[1] = await input();
|
||||
os[0] = "DARMOUTH";
|
||||
print("\n");
|
||||
sa[0] = 0;
|
||||
sa[1] = 0;
|
||||
p = Math.floor(Math.random() * 2);
|
||||
print(os[p] + " WON THE TOSS\n");
|
||||
if (p != 0) {
|
||||
print(os[1] + " ELECTS TO RECEIVE.\n");
|
||||
print("\n");
|
||||
} else {
|
||||
print("DO YOU ELECT TO KICK OR RECEIVE");
|
||||
while (1) {
|
||||
str = await input();
|
||||
print("\n");
|
||||
if (str == ls[1] || str == ls[2])
|
||||
break;
|
||||
print("INCORRECT ANSWER. PLEASE TYPE 'KICK' OR 'RECEIVE'");
|
||||
}
|
||||
e = (str == ls[1]) ? 1 : 2;
|
||||
if (e == 1)
|
||||
p = 1;
|
||||
}
|
||||
t = 0;
|
||||
start = 1;
|
||||
while (1) {
|
||||
if (start <= 1) {
|
||||
x = 40 + (1 - p) * 20;
|
||||
}
|
||||
if (start <= 2) {
|
||||
y = Math.floor(200 * Math.pow((Math.random() - 0.5), 3) + 55);
|
||||
print(" " + y + " " + ls[3] + " KICKOFF\n");
|
||||
x = x - fnf(1) * y;
|
||||
if (Math.abs(x - 50) >= 50) {
|
||||
print("TOUCHBACK FOR " + os[p] + ".\n");
|
||||
x = 20 + p * 60;
|
||||
start = 4;
|
||||
} else {
|
||||
start = 3;
|
||||
}
|
||||
}
|
||||
if (start <= 3) {
|
||||
y = Math.floor(50 * Math.pow(Math.random(), 2)) + (1 - p) * Math.floor(50 * Math.pow(Math.random(), 4));
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) < 50) {
|
||||
print(" " + y + " " + ls[3] + " RUNBACK\n");
|
||||
} else {
|
||||
print(ls[4]);
|
||||
offensive_td();
|
||||
start = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (start <= 4) {
|
||||
// First down
|
||||
show_position();
|
||||
}
|
||||
if (start <= 5) {
|
||||
x1 = x;
|
||||
d = 1;
|
||||
print("\n");
|
||||
print("FIRST DOWN " + os[p] + "***\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
}
|
||||
// New play
|
||||
t++;
|
||||
if (t == 30) {
|
||||
if (Math.random() <= 1.3) {
|
||||
print("GAME DELAYED. DOG ON FIELD.\n");
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
if (t >= 50 && Math.random() <= 0.2)
|
||||
break;
|
||||
if (p != 1) {
|
||||
// Opponent's play
|
||||
if (d <= 1) {
|
||||
z = Math.random() > 1 / 3 ? 1 : 3;
|
||||
} else if (d != 4) {
|
||||
if (10 + x - x1 < 5 || x < 5) {
|
||||
z = Math.random() > 1 / 3 ? 1 : 3;
|
||||
} else if (x <= 10) {
|
||||
a = Math.floor(2 * Math.random());
|
||||
z = 2 + a;
|
||||
} else if (x <= x1 || d < 3 || x < 45) {
|
||||
a = Math.floor(2 * Math.random());
|
||||
z = 2 + a * 2;
|
||||
} else {
|
||||
if (Math.random() > 1 / 4)
|
||||
z = 4;
|
||||
else
|
||||
z = 6;
|
||||
}
|
||||
} else {
|
||||
if (x <= 30) {
|
||||
z = 5;
|
||||
} else if (10 + x - x1 < 3 || x < 3) {
|
||||
z = Math.random() > 1 / 3 ? 1 : 3;
|
||||
} else {
|
||||
z = 7;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print("NEXT PLAY");
|
||||
while (1) {
|
||||
z = parseInt(await input());
|
||||
if (Math.abs(z - 4) <= 3)
|
||||
break;
|
||||
print("ILLEGAL PLAY NUMBER, RETYPE");
|
||||
}
|
||||
}
|
||||
f = 0;
|
||||
print(ls[z + 6] + ". ");
|
||||
r = Math.random() * (0.98 + fnf(1) * 0.02);
|
||||
r1 = Math.random();
|
||||
switch (z) {
|
||||
case 1: // Simple run
|
||||
case 2: // Tricky run
|
||||
if (z == 1) {
|
||||
y = Math.floor(24 * Math.pow(r - 0.5, 3) + 3);
|
||||
if (Math.random() >= 0.05) {
|
||||
routine = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
y = Math.floor(20 * r - 5);
|
||||
if (Math.random() > 0.1) {
|
||||
routine = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
f = -1;
|
||||
x3 = x;
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) < 50) {
|
||||
print("*** FUMBLE AFTER ");
|
||||
routine = 2;
|
||||
break;
|
||||
} else {
|
||||
print("*** FUMBLE.\n");
|
||||
routine = 4;
|
||||
break;
|
||||
}
|
||||
case 3: // Short pass
|
||||
case 4: // Long pass
|
||||
if (z == 3) {
|
||||
y = Math.floor(60 * Math.pow(r1 - 0.5, 3) + 10);
|
||||
} else {
|
||||
y = Math.floor(160 * Math.pow((r1 - 0.5), 3) + 30);
|
||||
}
|
||||
if (z == 3 && r < 0.05 || z == 4 && r < 0.1) {
|
||||
if (d != 4) {
|
||||
print("INTERCEPTED.\n");
|
||||
f = -1;
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) >= 50) {
|
||||
routine = 4;
|
||||
break;
|
||||
}
|
||||
routine = 3;
|
||||
break;
|
||||
} else {
|
||||
y = 0;
|
||||
if (Math.random() < 0.3) {
|
||||
print("BATTED DOWN. ");
|
||||
} else {
|
||||
print("INCOMPLETE. ");
|
||||
}
|
||||
routine = 1;
|
||||
break;
|
||||
}
|
||||
} else if (z == 4 && r < 0.3) {
|
||||
print("PASSER TACKLED. ");
|
||||
y = -Math.floor(15 * r1 + 3);
|
||||
routine = 1;
|
||||
break;
|
||||
} else if (z == 3 && r < 0.15) {
|
||||
print("PASSER TACLKED. ");
|
||||
y = -Math.floor(10 * r1);
|
||||
routine = 1;
|
||||
break;
|
||||
} else if (z == 3 && r < 0.55 || z == 4 && r < 0.75) {
|
||||
y = 0;
|
||||
if (Math.random() < 0.3) {
|
||||
print("BATTED DOWN. ");
|
||||
} else {
|
||||
print("INCOMPLETE. ");
|
||||
}
|
||||
routine = 1;
|
||||
break;
|
||||
} else {
|
||||
print("COMPLETE. ");
|
||||
routine = 1;
|
||||
break;
|
||||
}
|
||||
case 5: // Punt
|
||||
case 6: // Quick kick
|
||||
y = Math.floor(100 * Math.pow((r - 0.5), 3) + 35);
|
||||
if (d != 4)
|
||||
y = Math.floor(y * 1.3);
|
||||
print(" " + y + " " + ls[3] + " PUNT\n");
|
||||
if (Math.abs(x + y * fnf(1) - 50) < 50 && d >= 4) {
|
||||
y1 = Math.floor(Math.pow(r1, 2) * 20);
|
||||
print(" " + y1 + " " + ls[3] + " RUN BACK\n");
|
||||
y = y - y1;
|
||||
}
|
||||
f = -1;
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) >= 50) {
|
||||
routine = 4;
|
||||
break;
|
||||
}
|
||||
routine = 3;
|
||||
break;
|
||||
case 7: // Place kick
|
||||
y = Math.floor(100 * Math.pow((r - 0.5), 3) + 35);
|
||||
if (r1 <= 0.15) {
|
||||
print("KICK IS BLOCKED ***\n");
|
||||
x = x - 5 * fnf(1);
|
||||
p = 1 - p;
|
||||
start = 4;
|
||||
continue;
|
||||
}
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) >= 60) {
|
||||
if (r1 <= 0.5) {
|
||||
print("KICK IS OFF TO THE SIDE.\n");
|
||||
print(ls[18] + "\n");
|
||||
p = 1 - p;
|
||||
x = 20 + p * 60;
|
||||
start = 4;
|
||||
continue;
|
||||
} else {
|
||||
print("FIELD GOAL ***\n");
|
||||
sa[p] = sa[p] + 3;
|
||||
show_score();
|
||||
print(os[p] + " KICKS OFF\n");
|
||||
p = 1 - p;
|
||||
start = 1;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
print("KICK IS SHORT.\n");
|
||||
if (Math.abs(x - 50) >= 50) {
|
||||
// Touchback
|
||||
print(ls[18] + "\n");
|
||||
p = 1 - p;
|
||||
x = 20 + p * 60;
|
||||
start = 4;
|
||||
continue;
|
||||
}
|
||||
p = 1 - p;
|
||||
start = 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
// Gain or loss
|
||||
if (routine <= 1) {
|
||||
x3 = x;
|
||||
x = x + fnf(1) * y;
|
||||
if (Math.abs(x - 50) >= 50) {
|
||||
routine = 4;
|
||||
}
|
||||
}
|
||||
if (routine <= 2) {
|
||||
if (y != 0) {
|
||||
print(" " + Math.abs(y) + " " + ls[3]);
|
||||
if (y < 0)
|
||||
yt = -1;
|
||||
else if (y > 0)
|
||||
yt = 1;
|
||||
else
|
||||
yt = 0;
|
||||
print(ls[15 + yt]);
|
||||
if (Math.abs(x3 - 50) <= 40 && Math.random() < 0.1) {
|
||||
// Penalty
|
||||
p3 = Math.floor(2 * Math.random());
|
||||
print(os[p3] + " OFFSIDES -- PENALTY OF 5 YARDS.\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
if (p3 != 0) {
|
||||
print("DO YOU ACCEPT THE PENALTY");
|
||||
while (1) {
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
print("TYPE 'YES' OR 'NO'");
|
||||
}
|
||||
if (str == "YES") {
|
||||
f = 0;
|
||||
d = d - 1;
|
||||
if (p != p3)
|
||||
x = x3 + fnf(1) * 5;
|
||||
else
|
||||
x = x3 - fnf(1) * 5;
|
||||
}
|
||||
} else {
|
||||
// Opponent's strategy on penalty
|
||||
if ((p != 1 && (y <= 0 || f < 0 || fng(1) < 3 * d - 2))
|
||||
|| (p == 1 && ((y > 5 && f >= 0) || d < 4 || fng(1) >= 10))) {
|
||||
print("PENALTY REFUSED.\n");
|
||||
} else {
|
||||
print("PENALTY ACCEPTED.\n");
|
||||
f = 0;
|
||||
d = d - 1;
|
||||
if (p != p3)
|
||||
x = x3 + fnf(1) * 5;
|
||||
else
|
||||
x = x3 - fnf(1) * 5;
|
||||
}
|
||||
}
|
||||
routine = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (routine <= 3) {
|
||||
show_position();
|
||||
if (f != 0) {
|
||||
p = 1 - p;
|
||||
start = 5;
|
||||
continue;
|
||||
} else if (fng(1) >= 10) {
|
||||
start = 5;
|
||||
continue;
|
||||
} else if (d == 4) {
|
||||
p = 1 - p;
|
||||
start = 5;
|
||||
continue;
|
||||
} else {
|
||||
d++;
|
||||
print("DOWN: " + d + " ");
|
||||
if ((x1 - 50) * fnf(1) >= 40) {
|
||||
print("GOAL TO GO\n");
|
||||
} else {
|
||||
print("YARDS TO GO: " + (10 - fng(1)) + "\n");
|
||||
}
|
||||
print("\n");
|
||||
print("\n");
|
||||
start = 6;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (routine <= 4) {
|
||||
// Ball in end-zone
|
||||
e = (x >= 100) ? 1 : 0;
|
||||
switch (1 + e - f * 2 + p * 4) {
|
||||
case 1:
|
||||
case 5:
|
||||
// Safety
|
||||
sa[1 - p] = sa[1 - p] + 2;
|
||||
print(ls[19] + "\n");
|
||||
show_score();
|
||||
print(os[p] + " KICKS OFF FROM ITS 20 YARD LINE.\n");
|
||||
x = 20 + p * 60;
|
||||
p = 1 - p;
|
||||
start = 2;
|
||||
continue;
|
||||
case 3:
|
||||
case 6:
|
||||
// Defensive TD
|
||||
print(ls[17] + "FOR " + os[1 - p] + "***\n");
|
||||
p = 1 - p;
|
||||
// Fall-thru
|
||||
case 2:
|
||||
case 8:
|
||||
// Offensive TD
|
||||
print(ls[17] + "***\n");
|
||||
if (Math.random() <= 0.8) {
|
||||
sa[p] = sa[p] + 7;
|
||||
print("KICK IS GOOD.\n");
|
||||
} else {
|
||||
print("KICK IS OFF TO THE SIDE\n");
|
||||
sa[p] = sa[p] + 6;
|
||||
}
|
||||
show_score();
|
||||
print(os[p] + " KICKS OFF\n");
|
||||
p = 1 - p;
|
||||
start = 1;
|
||||
continue;
|
||||
case 4:
|
||||
case 7:
|
||||
// Touchback
|
||||
print(ls[18] + "\n");
|
||||
p = 1 - p;
|
||||
x = 20 + p * 60;
|
||||
start = 4;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
print("END OF GAME ***\n");
|
||||
print("FINAL SCORE: " + os[0] + ": " + sa[0] + " " + os[1] + ": " + sa[1] + "\n");
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user