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

Function displayForest

src/gamesbyexample/forestfiresim.py:90–107  ·  view source on GitHub ↗

Display the forest data structure on the screen.

(forest)

Source from the content-addressed store, hash-verified

88
89
90def displayForest(forest):
91 """Display the forest data structure on the screen."""
92 bext.goto(0, 0)
93 for y in range(forest['height']):
94 for x in range(forest['width']):
95 if forest[(x, y)] == TREE:
96 bext.fg('green')
97 print(TREE, end='')
98 elif forest[(x, y)] == FIRE:
99 bext.fg('red')
100 print(FIRE, end='')
101 elif forest[(x, y)] == EMPTY:
102 print(EMPTY, end='')
103 print()
104 bext.fg('reset') # Use the default font color.
105 print('Grow chance: {}% '.format(GROW_CHANCE * 100), end='')
106 print('Lightning chance: {}% '.format(FIRE_CHANCE * 100), end='')
107 print('Press Ctrl-C to quit.')
108
109
110# If this program was run (instead of imported), run the game:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected