mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Formatted the output texts to follow a more modern style
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
print("SLALOM".rjust(39))
|
print("Slalom".rjust(39))
|
||||||
print("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n".rjust(57))
|
print("Creative Computing Morristown, New Jersey\n\n\n".rjust(57))
|
||||||
|
|
||||||
medals = {
|
medals = {
|
||||||
"gold": 0,
|
"gold": 0,
|
||||||
@@ -19,64 +19,64 @@ def ask_int(question):
|
|||||||
return int(reply) if reply.isnumeric() else -1
|
return int(reply) if reply.isnumeric() else -1
|
||||||
|
|
||||||
def pre_run():
|
def pre_run():
|
||||||
print("\nTYPE \"INS\" FOR INSTRUCTIONS")
|
print("\nType \"INS\" for instructions")
|
||||||
print("TYPE \"MAX\" FOR APPROXIMATE MAXIMUM SPEEDS")
|
print("Type \"MAX\" for approximate maximum speeds")
|
||||||
print("TYPE \"RUN\" FOR THE BEGINNING OF THE RACE")
|
print("Type \"RUN\" for the beginning of the race")
|
||||||
cmd = ask("COMMAND--")
|
cmd = ask("Command--")
|
||||||
while cmd != "RUN":
|
while cmd != "RUN":
|
||||||
if cmd == "INS":
|
if cmd == "INS":
|
||||||
print("\n*** SLALOM: THIS IS THE 1976 WINTER OLYMPIC GIANT SLALOM. YOU ARE")
|
print("\n*** Slalom: This is the 1976 Winter Olypic Giant Slalom. You are")
|
||||||
print(" THE AMERICAN TEAM'S ONLY HOPE OF A GOLD MEDAL.\n")
|
print(" the American team's only hope for a gold medal.\n")
|
||||||
print(" 0 -- TYPE THIS IS YOU WANT TO SEE HOW LONG YOU'VE TAKEN.")
|
print(" 0 -- Type this if you want to see how long you've taken.")
|
||||||
print(" 1 -- TYPE THIS IF YOU WANT TO SPEED UP A LOT.")
|
print(" 1 -- Type this if you want to speed up a lot.")
|
||||||
print(" 2 -- TYPE THIS IF YOU WANT TO SPEED UP A LITTLE.")
|
print(" 2 -- Type this if you want to speed up a little.")
|
||||||
print(" 3 -- TYPE THIS IF YOU WANT TO SPEED UP A TEENSY.")
|
print(" 3 -- Type this if you want to speed up a teensy.")
|
||||||
print(" 4 -- TYPE THIS IF YOU WANT TO KEEP GOING THE SAME SPEED.")
|
print(" 4 -- Type this if you want to keep going the same speed.")
|
||||||
print(" 5 -- TYPE THIS IF YOU WANT TO CHECK A TEENSY.")
|
print(" 5 -- Type this if you want to check a teensy.")
|
||||||
print(" 6 -- TYPE THIS IF YOU WANT TO CHECK A LITTLE.")
|
print(" 6 -- Type this if you want to check a little.")
|
||||||
print(" 7 -- TYPE THIS IF YOU WANT TO CHECK A LOT.")
|
print(" 7 -- Type this if you want to check a lot.")
|
||||||
print(" 8 -- TYPE THIS IF YOU WANT TO CHEAT AND TRY TO SKIP A GATE.\n")
|
print(" 8 -- Type this if you want to cheat and try to skip a gate.\n")
|
||||||
print(" THE PLACE TO USE THESE OPTIONS IS WHEN THE COMPUTER ASKS:\n")
|
print(" The place to use these options is when the Computer asks:\n")
|
||||||
print("OPTION?\n")
|
print("Option?\n")
|
||||||
print(" GOOD LUCK!\n")
|
print(" Good Luck!\n")
|
||||||
cmd = ask("COMMAND--")
|
cmd = ask("Command--")
|
||||||
elif cmd == "MAX":
|
elif cmd == "MAX":
|
||||||
print("GATE MAX")
|
print("Gate Max")
|
||||||
print(" # M.P.H.")
|
print(" # M.P.H.")
|
||||||
print("----------")
|
print("----------")
|
||||||
for i in range(0, gates):
|
for i in range(0, gates):
|
||||||
print(f" {i + 1} {max_speeds[i]}")
|
print(f" {i + 1} {max_speeds[i]}")
|
||||||
cmd = ask("COMMAND--")
|
cmd = ask("Command--")
|
||||||
else:
|
else:
|
||||||
cmd = ask(f"\"{cmd}\" IS AN ILLEGAL COMMAND--RETRY")
|
cmd = ask(f"\"{cmd}\" is an illegal command--Retry")
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
global medals
|
global medals
|
||||||
print("THE STARTER COUNTS DOWN...5...4...3...2...1...GO!")
|
print("The starter counts down...5...4...3...2...1...Go!")
|
||||||
time = 0
|
time = 0
|
||||||
speed = int(random() * (18 - 9) + 9)
|
speed = int(random() * (18 - 9) + 9)
|
||||||
print("YOU'RE OFF")
|
print("You're off")
|
||||||
for i in range(0, gates):
|
for i in range(0, gates):
|
||||||
while True:
|
while True:
|
||||||
print(f"\nHERE COMES GATE #{i + 1}:")
|
print(f"\nHere comes gate #{i + 1}:")
|
||||||
print(f" {int(speed)}M.P.H.")
|
print(f" {int(speed)} M.P.H.")
|
||||||
old_speed = speed
|
old_speed = speed
|
||||||
opt = ask_int("OPTION")
|
opt = ask_int("Option")
|
||||||
while opt < 1 or opt > 8:
|
while opt < 1 or opt > 8:
|
||||||
if(opt == 0):
|
if(opt == 0):
|
||||||
print(f"YOU'VE TAKEN {int(time)}SECONDS.")
|
print(f"You've taken {int(time)} seconds.")
|
||||||
else:
|
else:
|
||||||
print("WHAT?")
|
print("What?")
|
||||||
opt = ask_int("OPTION")
|
opt = ask_int("Option")
|
||||||
|
|
||||||
if opt == 8:
|
if opt == 8:
|
||||||
print("***CHEAT")
|
print("***Cheat")
|
||||||
if random() < .7:
|
if random() < .7:
|
||||||
print("AN OFFICIAL CAUGHT YOU!")
|
print("An official caught you!")
|
||||||
print(f"YOU TOOK {int(time + random())}SECONDS.")
|
print(f"You took {int(time + random())} seconds.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("YOU MADE IT!")
|
print("You made it!")
|
||||||
time += 1.5
|
time += 1.5
|
||||||
else:
|
else:
|
||||||
match opt:
|
match opt:
|
||||||
@@ -97,69 +97,69 @@ def run():
|
|||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
speed -= int(random() * (10 - 5) + 5)
|
speed -= int(random() * (10 - 5) + 5)
|
||||||
print(f" {int(speed)}M.P.H.")
|
print(f" {int(speed)} M.P.H.")
|
||||||
if speed > max_speeds[i]:
|
if speed > max_speeds[i]:
|
||||||
if random() < ((speed - max_speeds[i]) * .1) + .2:
|
if random() < ((speed - max_speeds[i]) * .1) + .2:
|
||||||
print(f"YOU WENT OVER THE MAXIMUM SPEED AND {'SNAGGED A FLAG' if random() < .5 else 'WIPED OUT'}!")
|
print(f"You went over the maximum speed and {'snagged a flag' if random() < .5 else 'wiped out'}!")
|
||||||
print(f"YOU TOOK {int(time + random())}SECONDS")
|
print(f"You took {int(time + random())} seconds")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("YOU WENT OVER THE NAXIMUM SPEED AND MADE IT!")
|
print("You went over the maximum speed and made it!")
|
||||||
if speed > max_speeds[i] - 1:
|
if speed > max_speeds[i] - 1:
|
||||||
print("CLOSE ONE!")
|
print("Close one!")
|
||||||
if speed < 7:
|
if speed < 7:
|
||||||
print("LET'S BE REALISTIC, OK? LET'S GO BACK AND TRY AGAIN...")
|
print("Let's be realistic, ok? Let's go back and try again...")
|
||||||
speed = old_speed
|
speed = old_speed
|
||||||
else:
|
else:
|
||||||
time += max_speeds[i] - speed + 1
|
time += max_speeds[i] - speed + 1
|
||||||
if speed > max_speeds[i]:
|
if speed > max_speeds[i]:
|
||||||
time += .5
|
time += .5
|
||||||
break
|
break
|
||||||
print(f"\nYOU TOOK {int(time + random())}SECONDS.")
|
print(f"\nYou took {int(time + random())} seconds.")
|
||||||
avg = time / gates
|
avg = time / gates
|
||||||
if avg < 1.5 - (lvl * .1):
|
if avg < 1.5 - (lvl * .1):
|
||||||
print("YOU WON A GOLD MEDAL!")
|
print("Yout won a gold medal!")
|
||||||
medals["gold"] += 1
|
medals["gold"] += 1
|
||||||
elif avg < 2.9 - (lvl * .1):
|
elif avg < 2.9 - (lvl * .1):
|
||||||
print("YOU WON A SILVER MEDAL!")
|
print("You won a silver medal!")
|
||||||
medals["silver"] += 1
|
medals["silver"] += 1
|
||||||
elif avg < 4.4 - (lvl * .01):
|
elif avg < 4.4 - (lvl * .01):
|
||||||
print("YOU WON A BRONZE MEDAL!")
|
print("You won a bronze medal!")
|
||||||
medals["bronze"] += 1
|
medals["bronze"] += 1
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
gates = ask_int("HOW MANY GATES DOES THIS COURSE HAVE (1 TO 25)")
|
gates = ask_int("How many gates does this course have (1 to 25)")
|
||||||
if gates < 1:
|
if gates < 1:
|
||||||
print("TRY AGAIN,")
|
print("Try again,")
|
||||||
else:
|
else:
|
||||||
if(gates > 25):
|
if(gates > 25):
|
||||||
print("25 IS THE LIMIT.")
|
print("25 is the limit.")
|
||||||
break
|
break
|
||||||
|
|
||||||
pre_run()
|
pre_run()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
lvl = ask_int("RATE YOURSELF AS A SKIER, (1=WORST, 3=BEST)")
|
lvl = ask_int("Rate yourself as a skier, (1=Worst, 3=Best)")
|
||||||
if lvl < 1 or lvl > 3:
|
if lvl < 1 or lvl > 3:
|
||||||
print("THE BOUNDS ARE 1-3.")
|
print("The bounds are 1-3.")
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
run()
|
run()
|
||||||
while True:
|
while True:
|
||||||
answer = ask("DO YOU WANT TO PLAY AGAIN?")
|
answer = ask("Do you want to play again?")
|
||||||
if answer == "YES" or answer == "NO":
|
if answer == "YES" or answer == "NO":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("PLEASE TYPE 'YES' OR 'NO'")
|
print("Please type \"YES\" or \"NO\"")
|
||||||
if answer == "NO":
|
if answer == "NO":
|
||||||
break
|
break
|
||||||
|
|
||||||
print("THANKS FOR THE RACE")
|
print("Thanks for the race")
|
||||||
if medals["gold"] > 0:
|
if medals["gold"] > 0:
|
||||||
print(f"GOLD MEDALS: {medals['gold']}")
|
print(f"Gold medals: {medals['gold']}")
|
||||||
if medals["silver"] > 0:
|
if medals["silver"] > 0:
|
||||||
print(f"SILVER MEDALS: {medals['silver']}")
|
print(f"Silver medals: {medals['silver']}")
|
||||||
if medals["bronze"] > 0:
|
if medals["bronze"] > 0:
|
||||||
print(f"BRONZE MEDALS: {medals['bronze']}")
|
print(f"Bronze medals: {medals['bronze']}")
|
||||||
|
|||||||
Reference in New Issue
Block a user