mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 07:40:50 -08:00
print_with_tab / print_with_whitespace is trivial with Python string formatting and was mostly used in only 2 lines.
70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""Ported to Python by @iamtraction"""
|
|
|
|
from random import random
|
|
|
|
|
|
def direction(A, B, X, Y) -> None:
|
|
"""Prints the direction hint for finding the hurkle."""
|
|
|
|
print("GO ", end="")
|
|
if Y < B:
|
|
print("NORTH", end="")
|
|
elif Y > B:
|
|
print("SOUTH", end="")
|
|
|
|
if X < A:
|
|
print("EAST", end="")
|
|
elif X > A:
|
|
print("WEST", end="")
|
|
|
|
print()
|
|
|
|
|
|
def main() -> None:
|
|
print(" " * 33 + "HURKLE")
|
|
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
|
|
|
print("\n\n\n")
|
|
|
|
N = 5
|
|
G = 10
|
|
|
|
print()
|
|
print("A HURKLE IS HIDING ON A", G, "BY", G, "GRID. HOMEBASE")
|
|
print("ON THE GRID IS POINT 0,0 IN THE SOUTHWEST CORNER,")
|
|
print("AND ANY POINT ON THE GRID IS DESIGNATED BY A")
|
|
print("PAIR OF WHOLE NUMBERS SEPERATED BY A COMMA. THE FIRST")
|
|
print("NUMBER IS THE HORIZONTAL POSITION AND THE SECOND NUMBER")
|
|
print("IS THE VERTICAL POSITION. YOU MUST TRY TO")
|
|
print("GUESS THE HURKLE'S GRIDPOINT. YOU GET", N, "TRIES.")
|
|
print("AFTER EACH TRY, I WILL TELL YOU THE APPROXIMATE")
|
|
print("DIRECTION TO GO TO LOOK FOR THE HURKLE.")
|
|
print()
|
|
|
|
while True:
|
|
A = int(G * random())
|
|
B = int(G * random())
|
|
|
|
for k in range(0, N):
|
|
print("\nGUESS #" + str(k))
|
|
|
|
# read coordinates in `X, Y` format, split the string
|
|
# at `,`, and then parse the coordinates to `int` and
|
|
# store them in `X` and `Y` respectively.
|
|
[X, Y] = [int(c) for c in input("X,Y? ").split(",")]
|
|
|
|
if abs(X - A) + abs(Y - B) == 0:
|
|
print("\nYOU FOUND HIM IN", k + 1, "GUESSES!")
|
|
break
|
|
else:
|
|
direction(A, B, X, Y)
|
|
continue
|
|
|
|
print("\n\nLET'S PLAY AGAIN, HURKLE IS HIDING.\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|