forked from gatorfan95/adventures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
66 lines (53 loc) · 1.72 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
A classic text-based game. Just run the script with any python interpreter and have fun!
"""
import time, sys
def print_slow(txt, newline=True):
"""
Prints 'txt' to screen one character at a time like in the good ol' days.
"""
for x in txt: # cycle through the text one character at a time
print(x, end="", flush=True) # print one character, no new line, flush buffer
time.sleep(0.05)
if newline:
print() # go to new line
def yes_or_no(question):
"""
Prints 'question' to the screen and then prompts user for 'yes' or 'no' input.
"""
answer = input(question + "(y/n): ").lower().strip()
print()
while not answer in ["y", "yes", "n", "no"]:
print_slow("Y or N only, dude.")
answer = input(question + "(y/n):").lower().strip()
#print()
if answer[0] == "y":
return True
else:
return False
if __name__ == '__main__':
time.sleep(1)
print_slow("\nHello there! What is your name? ", False)
name = input()
# time.sleep(1)
greeting = "\nIt's nice to meet you, {}!"
comment1 = "Do you mind if... I ... "
comment2 = "Wait..."
comment3 = "Do you hear that noise?\n"
print_slow(greeting.format(name))
time.sleep(1)
print_slow(comment1)
time.sleep(1)
print_slow(comment2)
time.sleep(2)
print_slow(comment3)
if yes_or_no("What say you?"):
print_slow("Yeah, me too. The End")
else:
print_slow("Guess your ears are broken. The End")
time.sleep(1)
#Save to file and close
path = 'names.txt'
with open (path, 'w+') as names_file:
names_file.write(name)
print_slow(name + ", I think I just saved this!\n")