mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-07 02:24:33 -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:
7
81_Splat/README.md
Normal file
7
81_Splat/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Splat
|
||||
|
||||
As published in Basic Computer Games (1978)
|
||||
https://www.atariarchives.org/basicgames/showpage.php?page=151
|
||||
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
3
81_Splat/csharp/README.md
Normal file
3
81_Splat/csharp/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)
|
||||
3
81_Splat/java/README.md
Normal file
3
81_Splat/java/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Oracle Java](https://openjdk.java.net/)
|
||||
3
81_Splat/javascript/README.md
Normal file
3
81_Splat/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
81_Splat/javascript/splat.html
Normal file
9
81_Splat/javascript/splat.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>SPLAT</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="splat.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
283
81_Splat/javascript/splat.js
Normal file
283
81_Splat/javascript/splat.js
Normal file
@@ -0,0 +1,283 @@
|
||||
// SPLAT
|
||||
//
|
||||
// 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 aa = [];
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "SPLAT\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
for (i = 0; i <= 42; i++)
|
||||
aa[i] = 0;
|
||||
print("WELCOME TO 'SPLAT' -- THE GAME THAT SIMULATES A PARACHUTE\n");
|
||||
print("JUMP. TRY TO OPEN YOUR CHUTE AT THE LAST POSSIBLE\n");
|
||||
print("MOMENT WITHOUT GOING SPLAT.\n");
|
||||
while (1) {
|
||||
print("\n");
|
||||
print("\n");
|
||||
d1 = 0;
|
||||
v = 0;
|
||||
a = 0;
|
||||
n = 0;
|
||||
m = 0;
|
||||
d1 = Math.floor(9001 * Math.random() + 1000);
|
||||
print("SELECT YOUR OWN TERMINAL VELOCITY (YES OR NO)");
|
||||
while (1) {
|
||||
a1s = await input();
|
||||
if (a1s == "YES" || a1s == "NO")
|
||||
break;
|
||||
print("YES OR NO");
|
||||
}
|
||||
if (a1s == "YES") {
|
||||
print("WHAT TERMINAL VELOCITY (MI/HR)");
|
||||
v1 = parseFloat(await input());
|
||||
v1 = v1 * (5280 / 3600);
|
||||
} else {
|
||||
v1 = Math.floor(1000 * Math.random());
|
||||
print("OK. TERMINAL VELOCITY = " + v1 + " MI/HR\n");
|
||||
}
|
||||
v = v1 + ((v1 * Math.random()) / 20) - ((v1 * Math.random()) / 20);
|
||||
print("WANT TO SELECT ACCELERATION DUE TO GRAVITY (YES OR NO)");
|
||||
while (1) {
|
||||
b1s = await input();
|
||||
if (b1s == "YES" || b1s == "NO")
|
||||
break;
|
||||
print("YES OR NO");
|
||||
}
|
||||
if (b1s == "YES") {
|
||||
print("WHAT ACCELERATION (FT/SEC/SEC)");
|
||||
a2 = parseFloat(await input());
|
||||
} else {
|
||||
switch (Math.floor(1 + (10 * Math.random()))) {
|
||||
case 1:
|
||||
print("FINE. YOU'RE ON MERCURY. ACCELERATION=12.2 FT/SEC/SEC.\n");
|
||||
a2 = 12.2;
|
||||
break;
|
||||
case 2:
|
||||
print("ALL RIGHT. YOU'RE ON VENUS. ACCELERATION=28.3 FT/SEC/SEC.\n");
|
||||
a2 = 28.3;
|
||||
break;
|
||||
case 3:
|
||||
print("THEN YOU'RE ON EARTH. ACCELERATION=32.16 FT/SEC/SEC.\n");
|
||||
a2 = 32.16;
|
||||
break;
|
||||
case 4:
|
||||
print("FINE. YOU'RE ON THE MOON. ACCELERATION=5.15 FT/SEC/SEC.\n");
|
||||
a2 = 5.15;
|
||||
break;
|
||||
case 5:
|
||||
print("ALL RIGHT. YOU'RE ON MARS. ACCELERATION=12.5 FT/SEC/SEC.\n");
|
||||
a2 = 12.5;
|
||||
break;
|
||||
case 6:
|
||||
print("THEN YOU'RE ON JUPITER. ACCELERATION=85.2 FT/SEC/SEC.\n");
|
||||
a2 = 85.2;
|
||||
break;
|
||||
case 7:
|
||||
print("FINE. YOU'RE ON SATURN. ACCELERATION=37.6 FT/SEC/SEC.\n");
|
||||
a2 = 37.6;
|
||||
break;
|
||||
case 8:
|
||||
print("ALL RIGHT. YOU'RE ON URANUS. ACCELERATION=33.8 FT/SEC/SEC.\n");
|
||||
a2 = 33.8;
|
||||
break;
|
||||
case 9:
|
||||
print("THEN YOU'RE ON NEPTUNE. ACCELERATION=39.6 FT/SEC/SEC.\n");
|
||||
a2 = 39.6;
|
||||
break;
|
||||
case 10:
|
||||
print("FINE. YOU'RE ON THE SUN. ACCELERATION=896 FT/SEC/SEC.\n");
|
||||
a2 = 896;
|
||||
break;
|
||||
}
|
||||
}
|
||||
a = a2 + ((a2 * Math.random()) / 20) - ((a2 * Math.random()) / 20);
|
||||
print("\n");
|
||||
print(" ALTITUDE = " + d1 + " FT\n");
|
||||
print(" TERM. VELOCITY = " + v1 + " FT/SEC +/-5%\n");
|
||||
print(" ACCELERATION = " + a2 + " FT/SEC/SEC +/-5%\n");
|
||||
print("SET THE TIMER FOR YOUR FREEFALL.\n");
|
||||
print("HOW MANY SECONDS");
|
||||
t = parseFloat(await input());
|
||||
print("HERE WE GO.\n");
|
||||
print("\n");
|
||||
print("TIME (SEC)\tDIST TO FALL (FT)\n");
|
||||
print("==========\t=================\n");
|
||||
terminal = false;
|
||||
crash = false;
|
||||
for (i = 0; i <= t; i += t / 8) {
|
||||
if (i > v / a) {
|
||||
terminal = true;
|
||||
break;
|
||||
}
|
||||
d = d1 - ((a / 2) * Math.pow(i, 2));
|
||||
if (d <= 0) {
|
||||
print(Math.sqrt(2 * d1 / a) + "\tSPLAT\n");
|
||||
crash = true;
|
||||
break;
|
||||
}
|
||||
print(i + "\t" + d + "\n");
|
||||
}
|
||||
if (terminal) {
|
||||
print("TERMINAL VELOCITY REACHED AT T PLUS " + v/a + " SECONDS.\n");
|
||||
for (; i <= t; i += t / 8) {
|
||||
d = d1 - ((Math.pow(v, 2) / (2 * a)) + (v * (i - (v / a))));
|
||||
if (d <= 0) {
|
||||
print(((v / a) + ((d1 - (Math.pow(v, 2) / (2 * a))) / v)) + "\tSPLAT\n");
|
||||
crash = true;
|
||||
break;
|
||||
}
|
||||
print(i + "\t" + d + "\n");
|
||||
}
|
||||
}
|
||||
if (!crash) {
|
||||
print("CHUTE OPEN\n");
|
||||
k = 0;
|
||||
k1 = 0;
|
||||
for (j = 0; j <= 42; j++) {
|
||||
if (aa[j] == 0)
|
||||
break;
|
||||
k++;
|
||||
if (d < aa[j])
|
||||
k1++;
|
||||
}
|
||||
// In original jumps to line 540 (undefined) when table is full
|
||||
aa[j] = d;
|
||||
if (j <= 2) {
|
||||
print("AMAZING!!! NOT BAD FOR YOUR ");
|
||||
if (j == 0)
|
||||
print("1ST ");
|
||||
else if (j == 1)
|
||||
print("2ND ");
|
||||
else
|
||||
print("3RD ");
|
||||
print("SUCCESSFUL JUMP!!!\n");
|
||||
} else {
|
||||
if (k - k1 <= 0.1 * k) {
|
||||
print("WOW! THAT'S SOME JUMPING. OF THE " + k + " SUCCESSFUL JUMPS\n");
|
||||
print("BEFORE YOURS, ONLY " + (k - k1) + " OPENED THEIR CHUTES LOWER THAN\n");
|
||||
print("YOU DID.\n");
|
||||
} else if (k - k1 <= 0.25 * k) {
|
||||
print("PRETTY GOOD! " + k + " SUCCESSFUL JUMPS PRECEDED YOURS AND ONLY\n");
|
||||
print((k - k1) + " OF THEM GOT LOWER THAN YOU DID BEFORE THEIR CHUTES\n");
|
||||
print("OPENED.\n");
|
||||
} else if (k - k1 <= 0.5 * k) {
|
||||
print("NOT BAD. THERE HAVE BEEN " + k + " SUCCESSFUL JUMPS BEFORE YOURS.\n");
|
||||
print("YOU WERE BEATEN OUT BY " + (k - k1) + " OF THEM.\n");
|
||||
} else if (k - k1 <= 0.75 * k) {
|
||||
print("CONSERVATIVE, AREN'T YOU? YOU RANKED ONLY " + (k - k1) + " IN THE\n");
|
||||
print(k + " SUCCESSFUL JUMPS BEFORE YOURS.\n");
|
||||
} else if (k - k1 <= 0.9 * k) {
|
||||
print("HUMPH! DON'T YOU HAVE ANY SPORTING BLOOD? THERE WERE\n");
|
||||
print(k + " SUCCESSFUL JUMPS BEFORE YOURS AND YOU CAME IN " + k1 + "JUMPS\n");
|
||||
print("BETTER THAN THE WORST. SHAPE UP!!!\n");
|
||||
} else {
|
||||
print("HEY! YOU PULLED THE RIP CORD MUCH TOO SOON. " + k + " SUCCESSFUL\n");
|
||||
print("JUMPS BEFORE YOURS AND YOU CAME IN NUMBER " + (k - k1) + "! GET WITH IT!\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (Math.floor(1 + 10 * Math.random())) {
|
||||
case 1:
|
||||
print("REQUIESCAT IN PACE.\n");
|
||||
break;
|
||||
case 2:
|
||||
print("MAY THE ANGEL OF HEAVEN LEAD YOU INTO PARADISE.\n");
|
||||
break;
|
||||
case 3:
|
||||
print("REST IN PEACE.\n");
|
||||
break;
|
||||
case 4:
|
||||
print("SON-OF-A-GUN.\n");
|
||||
break;
|
||||
case 5:
|
||||
print("#%&&%!$\n");
|
||||
break;
|
||||
case 6:
|
||||
print("A KICK IN THE PANTS IS A BOOST IF YOU'RE HEADED RIGHT.\n");
|
||||
break;
|
||||
case 7:
|
||||
print("HMMM. SHOULD HAVE PICKED A SHORTER TIME.\n");
|
||||
break;
|
||||
case 8:
|
||||
print("MUTTER. MUTTER. MUTTER.\n");
|
||||
break;
|
||||
case 9:
|
||||
print("PUSHING UP DAISIES.\n");
|
||||
break;
|
||||
case 10:
|
||||
print("EASY COME, EASY GO.\n");
|
||||
break;
|
||||
}
|
||||
print("I'LL GIVE YOU ANOTHER CHANCE.\n");
|
||||
}
|
||||
while (1) {
|
||||
print("DO YOU WANT TO PLAY AGAIN");
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
print("YES OR NO\n");
|
||||
}
|
||||
if (str == "YES")
|
||||
continue;
|
||||
print("PLEASE");
|
||||
while (1) {
|
||||
str = await input();
|
||||
if (str == "YES" || str == "NO")
|
||||
break;
|
||||
print("YES OR NO");
|
||||
}
|
||||
if (str == "YES")
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
print("SSSSSSSSSS.\n");
|
||||
print("\n");
|
||||
}
|
||||
|
||||
main();
|
||||
3
81_Splat/pascal/README.md
Normal file
3
81_Splat/pascal/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))
|
||||
3
81_Splat/perl/README.md
Normal file
3
81_Splat/perl/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Perl](https://www.perl.org/)
|
||||
3
81_Splat/python/README.md
Normal file
3
81_Splat/python/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Python](https://www.python.org/about/)
|
||||
319
81_Splat/python/splat.py
Normal file
319
81_Splat/python/splat.py
Normal file
@@ -0,0 +1,319 @@
|
||||
"""
|
||||
SPLAT
|
||||
|
||||
Splat similates a parachute jump in which you try to open your parachute
|
||||
at the last possible moment without going splat! You may select your own
|
||||
terminal velocity or let the computer do it for you. You may also select
|
||||
the acceleration due to gravity or, again, let the computer do it
|
||||
in which case you might wind up on any one of the eight planets (out to
|
||||
Neptune), the moon, or the sun.
|
||||
|
||||
The computer then tells you the height you're jumping from and asks for
|
||||
the seconds of free fall. It then divides your free fall time into eight
|
||||
intervals and gives you progress reports on the way down. The computer
|
||||
also keeps track of all prior jumps and lets you know how you compared
|
||||
with previous successful jumps. If you want to recall information from
|
||||
previous runs, then you should store the array `successful_jumps` on
|
||||
disk and read it before each run.
|
||||
|
||||
John Yegge created this program while at the Oak Ridge Associated
|
||||
Universities.
|
||||
|
||||
Ported in 2021 by Jonas Nockert / @lemonad
|
||||
|
||||
"""
|
||||
from math import sqrt
|
||||
from random import choice, random, uniform
|
||||
|
||||
PAGE_WIDTH = 72
|
||||
|
||||
|
||||
def numeric_input(question, default=0):
|
||||
"""Ask user for a numeric value."""
|
||||
while True:
|
||||
answer = input(f"{question} [{default}]: ").strip() or default
|
||||
try:
|
||||
return float(answer)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def yes_no_input(question, default="YES"):
|
||||
"""Ask user a yes/no question and returns True if yes, otherwise False."""
|
||||
answer = input(f"{question} (YES OR NO) [{default}]: ").strip() or default
|
||||
while answer.lower() not in ["n", "no", "y", "yes"]:
|
||||
answer = input(f"YES OR NO [{default}]: ").strip() or default
|
||||
return answer.lower() in ["y", "yes"]
|
||||
|
||||
|
||||
def get_terminal_velocity():
|
||||
"""Terminal velocity by user or picked by computer."""
|
||||
if yes_no_input("SELECT YOUR OWN TERMINAL VELOCITY", default="NO"):
|
||||
v1 = numeric_input("WHAT TERMINAL VELOCITY (MI/HR)", default=100)
|
||||
else:
|
||||
# Computer picks 0-1000 terminal velocity.
|
||||
v1 = int(1000 * random())
|
||||
print(f"OK. TERMINAL VELOCITY = {v1} MI/HR")
|
||||
|
||||
# Convert miles/h to feet/s.
|
||||
return v1 * (5280 / 3600)
|
||||
|
||||
|
||||
def get_acceleration():
|
||||
"""Acceleration due to gravity by user or picked by computer."""
|
||||
if yes_no_input("WANT TO SELECT ACCELERATION DUE TO GRAVITY", default="NO"):
|
||||
a2 = numeric_input("WHAT ACCELERATION (FT/SEC/SEC)", default=32.16)
|
||||
else:
|
||||
body, a2 = pick_random_celestial_body()
|
||||
print(f"FINE. YOU'RE ON {body}. ACCELERATION={a2} FT/SEC/SEC.")
|
||||
return a2
|
||||
|
||||
|
||||
def get_freefall_time():
|
||||
"""User-guessed freefall time.
|
||||
|
||||
The idea of the game is to pick a freefall time, given initial
|
||||
altitude, terminal velocity and acceleration, so the parachute
|
||||
as close to the ground as possible without going splat.
|
||||
"""
|
||||
t_freefall = 0
|
||||
# A zero or negative freefall time is not handled by the motion
|
||||
# equations during the jump.
|
||||
while t_freefall <= 0:
|
||||
t_freefall = numeric_input("HOW MANY SECONDS", default=10)
|
||||
return t_freefall
|
||||
|
||||
|
||||
def jump():
|
||||
"""Simulate a jump and returns the altitude where the chute opened.
|
||||
|
||||
The idea is to open the chute as late as possible -- but not too late.
|
||||
"""
|
||||
v = 0 # Terminal velocity.
|
||||
a = 0 # Acceleration.
|
||||
initial_altitude = int(9001 * random() + 1000)
|
||||
|
||||
v1 = get_terminal_velocity()
|
||||
# Actual terminal velocity is +/-5% of v1.
|
||||
v = v1 * uniform(0.95, 1.05)
|
||||
|
||||
a2 = get_acceleration()
|
||||
# Actual acceleration is +/-5% of a2.
|
||||
a = a2 * uniform(0.95, 1.05)
|
||||
|
||||
print(
|
||||
"\n"
|
||||
f" ALTITUDE = {initial_altitude} FT\n"
|
||||
f" TERM. VELOCITY = {v1:.2f} FT/SEC +/-5%\n"
|
||||
f" ACCELERATION = {a2:.2f} FT/SEC/SEC +/-5%\n"
|
||||
"SET THE TIMER FOR YOUR FREEFALL."
|
||||
)
|
||||
t_freefall = get_freefall_time()
|
||||
print(
|
||||
"HERE WE GO.\n\n"
|
||||
"TIME (SEC)\tDIST TO FALL (FT)\n"
|
||||
"==========\t================="
|
||||
)
|
||||
|
||||
terminal_velocity_reached = False
|
||||
is_splat = False
|
||||
for i in range(9):
|
||||
# Divide time for freefall into 8 intervals.
|
||||
t = i * (t_freefall / 8)
|
||||
# From the first equation of motion, v = v_0 + a * delta_t, with
|
||||
# initial velocity v_0 = 0, we can get the time when terminal velocity
|
||||
# is reached: delta_t = v / a.
|
||||
if t > v / a:
|
||||
if not terminal_velocity_reached:
|
||||
print(f"TERMINAL VELOCITY REACHED AT T PLUS {v / a:.2f} SECONDS.")
|
||||
terminal_velocity_reached = True
|
||||
# After having reached terminal velocity, the displacement is
|
||||
# composed of two parts:
|
||||
# 1. Displacement up to reaching terminal velocity:
|
||||
# From the third equation of motion, v^2 = v_0^2 + 2 * a * d,
|
||||
# with v_0 = 0, we can get the displacement using
|
||||
# d1 = v^2 / (2 * a).
|
||||
# 2. Displacement beyond having reached terminal velocity:
|
||||
# here, the displacement is just a function of the terminal
|
||||
# velocity and the time passed after having reached terminal
|
||||
# velocity: d2 = v * (t - t_reached_term_vel)
|
||||
d1 = (v ** 2) / (2 * a)
|
||||
d2 = v * (t - (v / a))
|
||||
altitude = initial_altitude - (d1 + d2)
|
||||
if altitude <= 0:
|
||||
# Time taken for an object to fall to the ground given
|
||||
# an initial altitude is composed of two parts after having
|
||||
# reached terminal velocity:
|
||||
# 1. time up to reaching terminal velocity: t1 = v / a
|
||||
# 2. time beyond having reached terminal velocity:
|
||||
# here, the altitude that remains after having reached
|
||||
# terminal velocity can just be divided by the constant
|
||||
# terminal velocity to get the time it takes to reach the
|
||||
# ground: t2 = altitude_remaining / v
|
||||
t1 = v / a
|
||||
t2 = (initial_altitude - d1) / v
|
||||
print_splat(t1 + t2)
|
||||
is_splat = True
|
||||
break
|
||||
else:
|
||||
# 1. Displacement before reaching terminal velocity:
|
||||
# From the second equation of motion,
|
||||
# d = v_0 * t + 0.5 * a * t^2, with v_0 = 0, we can get
|
||||
# the displacement using d1 = a / 2 * t^2
|
||||
d1 = (a / 2) * (t ** 2)
|
||||
altitude = initial_altitude - d1
|
||||
if altitude <= 0:
|
||||
# Time taken for an object to fall to the ground given that
|
||||
# it never reaches terminal velocity can be calculated by
|
||||
# using the second equation of motion:
|
||||
# d = v_0 * t + 0.5 * a * t^2, with v_0 = 0, which
|
||||
# when solved for t becomes
|
||||
# t1 = sqrt(2 * d / a).
|
||||
t1 = sqrt(2 * initial_altitude / a)
|
||||
print_splat(t1)
|
||||
is_splat = True
|
||||
break
|
||||
print(f"{t:.2f}\t\t{altitude:.1f}")
|
||||
|
||||
if not is_splat:
|
||||
print("CHUTE OPEN")
|
||||
return altitude
|
||||
|
||||
|
||||
def pick_random_celestial_body():
|
||||
"""Pick a random planet, the moon, or the sun with associated gravity."""
|
||||
body, gravity = choice(
|
||||
[
|
||||
("MERCURY", 12.2),
|
||||
("VENUS", 28.3),
|
||||
("EARTH", 32.16),
|
||||
("THE MOON", 5.15),
|
||||
("MARS", 12.5),
|
||||
("JUPITER", 85.2),
|
||||
("SATURN", 37.6),
|
||||
("URANUS", 33.8),
|
||||
("NEPTUNE", 39.6),
|
||||
("THE SUN", 896.0),
|
||||
]
|
||||
)
|
||||
return body, gravity
|
||||
|
||||
|
||||
def jump_stats(previous_jumps, chute_altitude):
|
||||
"""Compare altitude when chute opened with previous successful jumps.
|
||||
|
||||
Return the number of previous jumps and the number of times
|
||||
the current jump is better.
|
||||
"""
|
||||
n_previous_jumps = len(previous_jumps)
|
||||
n_better = sum([1 for pj in previous_jumps if chute_altitude < pj])
|
||||
return n_previous_jumps, n_better
|
||||
|
||||
|
||||
def print_splat(time_on_impact):
|
||||
"""Parachute opened too late!"""
|
||||
print(f"{time_on_impact:.2f}\t\tSPLAT")
|
||||
print(
|
||||
choice(
|
||||
[
|
||||
"REQUIESCAT IN PACE.",
|
||||
"MAY THE ANGEL OF HEAVEN LEAD YOU INTO PARADISE.",
|
||||
"REST IN PEACE.",
|
||||
"SON-OF-A-GUN.",
|
||||
"#$%&&%!$",
|
||||
"A KICK IN THE PANTS IS A BOOST IF YOU'RE HEADED RIGHT.",
|
||||
"HMMM. SHOULD HAVE PICKED A SHORTER TIME.",
|
||||
"MUTTER. MUTTER. MUTTER.",
|
||||
"PUSHING UP DAISIES.",
|
||||
"EASY COME, EASY GO.",
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def print_results(n_previous_jumps, n_better):
|
||||
"""Compare current jump to previous successful jumps."""
|
||||
k = n_previous_jumps
|
||||
k1 = n_better
|
||||
n_jumps = k + 1
|
||||
if n_jumps <= 3:
|
||||
order = ["1ST", "2ND", "3RD"]
|
||||
nth = order[n_jumps - 1]
|
||||
print(f"AMAZING!!! NOT BAD FOR YOUR {nth} SUCCESSFUL JUMP!!!")
|
||||
elif k - k1 <= 0.1 * k:
|
||||
print(
|
||||
f"WOW! THAT'S SOME JUMPING. OF THE {k} SUCCESSFUL JUMPS\n"
|
||||
f"BEFORE YOURS, ONLY {k - k1} OPENED THEIR CHUTES LOWER THAN\n"
|
||||
"YOU DID."
|
||||
)
|
||||
elif k - k1 <= 0.25 * k:
|
||||
print(
|
||||
f"PRETTY GOOD! {k} SUCCESSFUL JUMPS PRECEDED YOURS AND ONLY\n"
|
||||
f"{k - k1} OF THEM GOT LOWER THAN YOU DID BEFORE THEIR CHUTES\n"
|
||||
"OPENED."
|
||||
)
|
||||
elif k - k1 <= 0.5 * k:
|
||||
print(
|
||||
f"NOT BAD. THERE HAVE BEEN {k} SUCCESSFUL JUMPS BEFORE YOURS.\n"
|
||||
f"YOU WERE BEATEN OUT BY {k - k1} OF THEM."
|
||||
)
|
||||
elif k - k1 <= 0.75 * k:
|
||||
print(
|
||||
f"CONSERVATIVE, AREN'T YOU? YOU RANKED ONLY {k - k1} IN THE\n"
|
||||
f"{k} SUCCESSFUL JUMPS BEFORE YOURS."
|
||||
)
|
||||
elif k - k1 <= 0.9 * k:
|
||||
print(
|
||||
"HUMPH! DON'T YOU HAVE ANY SPORTING BLOOD? THERE WERE\n"
|
||||
f"{k} SUCCESSFUL JUMPS BEFORE YOURS AND YOU CAME IN {k1} JUMPS\n"
|
||||
"BETTER THAN THE WORST. SHAPE UP!!!"
|
||||
)
|
||||
else:
|
||||
print(
|
||||
f"HEY! YOU PULLED THE RIP CORD MUCH TOO SOON. {k} SUCCESSFUL\n"
|
||||
f"JUMPS BEFORE YOURS AND YOU CAME IN NUMBER {k - k1}!"
|
||||
" GET WITH IT!"
|
||||
)
|
||||
|
||||
|
||||
def print_centered(msg):
|
||||
"""Print centered text."""
|
||||
spaces = " " * ((PAGE_WIDTH - len(msg)) // 2)
|
||||
print(spaces + msg)
|
||||
|
||||
|
||||
def print_header():
|
||||
print_centered("SPLAT")
|
||||
print_centered("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
||||
print(
|
||||
"\n\n\n"
|
||||
"WELCOME TO 'SPLAT' -- THE GAME THAT SIMULATES A PARACHUTE\n"
|
||||
"JUMP. TRY TO OPEN YOUR CHUTE AT THE LAST POSSIBLE\n"
|
||||
"MOMENT WITHOUT GOING SPLAT.\n\n"
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Main program.
|
||||
#
|
||||
|
||||
print_header()
|
||||
|
||||
successful_jumps = []
|
||||
while True:
|
||||
chute_altitude = jump()
|
||||
if chute_altitude > 0:
|
||||
# We want the statistics on previous jumps (i.e. not including the
|
||||
# current jump.)
|
||||
n_previous_jumps, n_better = jump_stats(successful_jumps, chute_altitude)
|
||||
successful_jumps.append(chute_altitude)
|
||||
print_results(n_previous_jumps, n_better)
|
||||
else:
|
||||
# Splat!
|
||||
print("I'LL GIVE YOU ANOTHER CHANCE.")
|
||||
z = yes_no_input("DO YOU WANT TO PLAY AGAIN")
|
||||
if not z:
|
||||
z = yes_no_input("PLEASE")
|
||||
if not z:
|
||||
print("SSSSSSSSSS.")
|
||||
break
|
||||
3
81_Splat/ruby/README.md
Normal file
3
81_Splat/ruby/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Ruby](https://www.ruby-lang.org/en/)
|
||||
128
81_Splat/splat.bas
Normal file
128
81_Splat/splat.bas
Normal file
@@ -0,0 +1,128 @@
|
||||
10 PRINT TAB(33);"SPLAT"
|
||||
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
40 PRINT:PRINT:PRINT
|
||||
50 DIM A(42)
|
||||
95 PRINT "WELCOME TO 'SPLAT' -- THE GAME THAT SIMULATES A PARACHUTE"
|
||||
96 PRINT "JUMP. TRY TO OPEN YOUR CHUTE AT THE LAST POSSIBLE"
|
||||
97 PRINT "MOMENT WITHOUT GOING SPLAT."
|
||||
118 PRINT:PRINT:D1=0:V=0:A=0:N=0:M=0:D1=INT(9001*RND(1)+1000)
|
||||
119 PRINT "SELECT YOUR OWN TERMINAL VELOCITY (YES OR NO)";:INPUT A1$
|
||||
120 IF A1$="NO" THEN 128
|
||||
121 IF A1$<>"YES" THEN PRINT "YES OR NO";:INPUT A1$:GOTO 120
|
||||
123 PRINT "WHAT TERMINAL VELOCITY (MI/HR)";:INPUT V1
|
||||
125 V1=V1*(5280/3600):V=V1+((V1*RND(1))/20)-((V1*RND(1))/20):GOTO 135
|
||||
128 V1=INT(1000*RND(1))
|
||||
130 PRINT "OK. TERMINAL VELOCITY ="V1"MI/HR"
|
||||
131 V1=V1*(5280/3600):V=V1+((V1*RND(1))/20)-((V1*RND(1))/20)
|
||||
135 PRINT "WANT TO SELECT ACCELERATION DUE TO GRAVITY (YES OR NO)";
|
||||
136 INPUT B1$
|
||||
140 IF B1$="NO" THEN 150
|
||||
141 IF B1$<>"YES" THEN PRINT "YES OR NO";:INPUT B1$:GOTO 140
|
||||
143 PRINT "WHAT ACCELERATION (FT/SEC/SEC)";:INPUT A2
|
||||
145 A=A2+((A2*RND(1))/20)-((A2*RND(1))/20):GOTO 205
|
||||
150 ON INT(1+(10*RND(1)))GOTO 151,152,153,154,155,156,157,158,159,160
|
||||
151 PRINT"FINE. YOU'RE ON MERCURY. ACCELERATION=12.2 FT/SEC/SEC.":GOTO 161
|
||||
152 PRINT"ALL RIGHT. YOU'RE ON VENUS. ACCELERATION=28.3 FT/SEC/SEC.":GOTO 162
|
||||
153 PRINT "THEN YOU'RE ON EARTH. ACCELERATION=32.16 FT/SEC/SEC.":GOTO 163
|
||||
154 PRINT"FINE. YOU'RE ON THE MOON. ACCELERATION=5.15 FT/SEC/SEC.":GOTO 164
|
||||
155 PRINT"ALL RIGHT. YOU'RE ON MARS. ACCELERATION=12.5 FT/SEC/SEC.":GOTO 165
|
||||
156 PRINT"THEN YOU'RE ON JUPITER. ACCELERATION=85.2 FT/SEC/SEC.":GOTO 166
|
||||
157 PRINT"FINE. YOU'RE ON SATURN. ACCELERATION=37.6 FT/SEC/SEC.":GOTO 167
|
||||
158 PRINT"ALL RIGHT. YOU'RE ON URANUS. ACCELERATION=33.8 FT/SEC/SEC.":GOTO 168
|
||||
159 PRINT"THEN YOU'RE ON NEPTUNE. ACCELERATION=39.6 FT/SEC/SEC.":GOTO 169
|
||||
160 PRINT"FINE. YOU'RE ON THE SUN. ACCELERATION=896 FT/SEC/SEC.":GOTO 170
|
||||
161 A2=12.2:GOTO 145
|
||||
162 A2=28.3:GOTO 145
|
||||
163 A2=32.16:GOTO 145
|
||||
164 A2=5.15:GOTO 145
|
||||
165 A2=12.5:GOTO 145
|
||||
166 A2=85.2:GOTO 145
|
||||
167 A2=37.6:GOTO 145
|
||||
168 A2=33.8 :GOTO 145
|
||||
169 A2=39.6:GOTO 145
|
||||
170 A2=896:GOTO 145
|
||||
205 PRINT
|
||||
206 PRINT " ALTITUDE ="D1"FT"
|
||||
207 PRINT " TERM. VELOCITY ="V1"FT/SEC +/-5%"
|
||||
208 PRINT " ACCELERATION ="A2"FT/SEC/SEC +/-5%"
|
||||
210 PRINT "SET THE TIMER FOR YOUR FREEFALL."
|
||||
211 PRINT "HOW MANY SECONDS";:INPUT T
|
||||
215 PRINT "HERE WE GO."
|
||||
217 PRINT
|
||||
218 PRINT "TIME (SEC)","DIST TO FALL (FT)"
|
||||
219 PRINT "==========","================="
|
||||
300 FOR I=0 TO T STEP (T/8)
|
||||
310 IF I>V/A THEN 400
|
||||
320 D=D1-((A/2)*I^2)
|
||||
330 IF D<=0 THEN 1000
|
||||
340 PRINT I,D
|
||||
350 NEXT I
|
||||
360 GOTO 500
|
||||
400 PRINT "TERMINAL VELOCITY REACHED AT T PLUS"V/A"SECONDS."
|
||||
405 FOR I=I TO T STEP (T/8)
|
||||
410 D=D1-((V^2/(2*A))+(V*(I-(V/A))))
|
||||
420 IF D<=0 THEN 1010
|
||||
430 PRINT I,D
|
||||
440 NEXT I
|
||||
500 PRINT "CHUTE OPEN"
|
||||
510 K=0:K1=0
|
||||
550 FOR J=0 TO 42
|
||||
555 IF A(J)=0 THEN 620
|
||||
560 K=K+1
|
||||
570 IF D>=A(J) THEN 600
|
||||
580 K1=K1+1
|
||||
600 NEXT J
|
||||
610 GOTO 540
|
||||
620 A(J)=D
|
||||
630 IF J>2 THEN 650
|
||||
635 PRINT "AMAZING!!! NOT BAD FOR YOUR ";
|
||||
636 IF J=0 THEN PRINT "1ST ";
|
||||
637 IF J=1 THEN PRINT "2ND ";
|
||||
638 IF J=2 THEN PRINT "3RD ";
|
||||
639 PRINT "SUCCESSFUL JUMP!!!":GOTO 2000
|
||||
650 IF K-K1<=.1*K THEN 700
|
||||
660 IF K-K1<=.25*K THEN 710
|
||||
670 IF K-K1<=.5*K THEN 720
|
||||
680 IF K-K1<=.75*K THEN 730
|
||||
690 IF K-K1<=.9*K THEN 740
|
||||
695 GOTO 750
|
||||
700 PRINT "WOW! THAT'S SOME JUMPING. OF THE"K"SUCCESSFUL JUMPS"
|
||||
701 PRINT "BEFORE YOURS, ONLY"K-K1"OPENED THEIR CHUTES LOWER THAN"
|
||||
702 PRINT "YOU DID."
|
||||
703 GOTO 2000
|
||||
710 PRINT "PRETTY GOOD! " K"SUCCESSFUL JUMPS PRECEDED YOURS AND ONLY"
|
||||
711 PRINT K-K1" OF THEM GOT LOWER THAN YOU DID BEFORE THEIR CHUTES"
|
||||
712 PRINT "OPENED." :GOTO 2000
|
||||
720 PRINT "NOT BAD. THERE HAVE BEEN"K"SUCCESSFUL JUMPS BEFORE YOURS."
|
||||
721 PRINT"YOU WERE BEATEN OUT BY"K-K1"OF THEM.":GOTO 2000
|
||||
730 PRINT "CONSERVATIVE, AREN'T YOU? YOU RANKED ONLY"K-K1"IN THE"
|
||||
731 PRINT K"SUCCESSFUL JUMPS BEFORE YOURS.":GOTO 2000
|
||||
740 PRINT "HUMPH! DON'T YOU HAVE ANY SPORTING BLOOD? THERE WERE"
|
||||
741 PRINT K"SUCCESSFUL JUMPS BEFORE YOURS AND YOU CAME IN"K1"JUMPS"
|
||||
742 PRINT "BETTER THAN THE WORST. SHAPE UP!!!":GOTO 2000
|
||||
750 PRINT "HEY! YOU PULLED THE RIP CORD MUCH TOO SOON. "K"SUCCESSFUL"
|
||||
751 PRINT "JUMPS BEFORE YOURS AND YOU CAME IN NUMBER"K-K1"! GET WITH IT!"
|
||||
752 GOTO 2000
|
||||
800 PRINT "REQUIESCAT IN PACE.":GOTO 1950
|
||||
801 PRINT "MAY THE ANGEL OF HEAVEN LEAD YOU INTO PARADISE.":GOTO 1950
|
||||
802 PRINT "REST IN PEACE.":GOTO 1950
|
||||
803 PRINT "SON-OF-A-GUN.":GOTO 1950
|
||||
804 PRINT "#$%&&%!$":GOTO 1950
|
||||
805 PRINT "A KICK IN THE PANTS IS A BOOST IF YOU'RE HEADED RIGHT.":GOTO 1950
|
||||
806 PRINT "HMMM. SHOULD HAVE PICKED A SHORTER TIME.":GOTO 1950
|
||||
807 PRINT "MUTTER. MUTTER. MUTTER.":GOTO 1950
|
||||
808 PRINT "PUSHING UP DAISIES.":GOTO 1950
|
||||
809 PRINT "EASY COME, EASY GO.":GOTO 1950
|
||||
1000 PRINT SQR(2*D1/A),"SPLAT"
|
||||
1005 ON INT(1+(10*RND(1)))GOTO 800,801,802,803,804,805,806,807,808,809
|
||||
1010 PRINT (V/A)+((D1-(V^2/(2*A)))/V),"SPLAT"
|
||||
1020 GOTO 1005
|
||||
1950 PRINT "I'LL GIVE YOU ANOTHER CHANCE.":GOTO 2000
|
||||
2000 PRINT "DO YOU WANT TO PLAY AGAIN";:INPUT Z$
|
||||
2001 IF Z$="YES" THEN 118
|
||||
2002 IF Z$="NO" THEN 2005
|
||||
2003 PRINT "YES OR NO":GOTO 2000
|
||||
2005 PRINT "PLEASE";:INPUT Z$:IF Z$="YES" THEN 118
|
||||
2006 IF Z$<>"NO" THEN PRINT "YES OR NO ";:GOTO 2005
|
||||
2007 PRINT "SSSSSSSSSS.":PRINT:GOTO 2046
|
||||
2046 END
|
||||
3
81_Splat/vbnet/README.md
Normal file
3
81_Splat/vbnet/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)
|
||||
Reference in New Issue
Block a user