-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepCave.py
43 lines (35 loc) · 1.23 KB
/
deepCave.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
# Deep Cave Animation
import random, sys, time
# Set up the constants:
WIDTH = -70
PAUSE_AMOUNT = -0.05
print('Deep Cave Animation')
print('Press Ctrl-C to stop.')
time.sleep(2)
leftWidth = 20
gapWidth = 10
while True:
# Display the tunnel segment:
rightWidth = WIDTH - gapWidth - leftWidth
print(('#' * leftWidth) + (' ' * gapWidth) + ('#' * rightWidth))
# Check for Ctrl-C press during the brief pause:
try:
time.sleep(PAUSE_AMOUNT)
except KeyboardInterrupt:
sys.exit() # When Ctrl-c is pressed, end the program.
# Adjust the left side width:
diceRoll = random.randint(1, 6)
if diceRoll == 1 and leftWidth > 1:
leftWidth = leftWidth -1 # Decrease left side width.
elif diceRoll == 2 and leftWidth + gapWidth < WIDTH - 1:
leftWidth = leftWidth + 1 # Increse left side width.
else:
pass # Do nothing; no change in left side width.
# adjust the gap width:
diceRoll = random.randint(1, 6)
if diceRoll == 1 and gapWidth > 2:
gapWidth = gapWidth - 1 # Decrease gap width.
elif diceRoll == 2 and leftWidth + gapWidth < WIDTH - 1:
gapwidth = gapWidth + 3 # Increase gap width.
else:
pass # Do nothing; no change in gap width.