MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/ducklings.py:42–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40
41
42def main():
43 print('Duckling Screensaver, by Al Sweigart')
44 print('Press Ctrl-C to quit...')
45 time.sleep(2)
46
47 ducklingLanes = [None] * (WIDTH // DUCKLING_WIDTH)
48
49 while True: # Main program loop.
50 for laneNum, ducklingObj in enumerate(ducklingLanes):
51 # See if we should create a duckling in this lane:
52 if (ducklingObj == None and random.random() <= DENSITY):
53 # Place a duckling in this lane:
54 ducklingObj = Duckling()
55 ducklingLanes[laneNum] = ducklingObj
56
57 if ducklingObj != None:
58 # Draw a duckling if there is one in this lane:
59 print(ducklingObj.getNextBodyPart(), end='')
60 # Delete the duckling if we've finished drawing it:
61 if ducklingObj.partToDisplayNext == None:
62 ducklingLanes[laneNum] = None
63 else:
64 # Draw five spaces since there is no duckling here.
65 print(' ' * DUCKLING_WIDTH, end='')
66
67 print() # Print a newline.
68 sys.stdout.flush() # Make sure text appears on the screen.
69 time.sleep(PAUSE)
70
71
72class Duckling:

Callers 1

ducklings.pyFile · 0.70

Calls 2

getNextBodyPartMethod · 0.95
DucklingClass · 0.70

Tested by

no test coverage detected