Display the map, with visited intersections and the player's current position.
(playerx, playery, visitedIntersections)
| 109 | |
| 110 | |
| 111 | def displayMap(playerx, playery, visitedIntersections): |
| 112 | """Display the map, with visited intersections and the player's |
| 113 | current position.""" |
| 114 | # Print the avenue names at the top: |
| 115 | print(' ', end='') |
| 116 | for x in range(WIDTH): |
| 117 | print(x, getOrdIndicator(x), sep='', end='') |
| 118 | if x < 10: |
| 119 | # Single-digit names need an extra space at the end: |
| 120 | print(' ', end='') |
| 121 | print() # Print a newline. |
| 122 | |
| 123 | print(' ', end='') |
| 124 | for x in range(WIDTH): |
| 125 | print('Ave ', end='') |
| 126 | print() # Print a newline. |
| 127 | |
| 128 | # Print the lines for all the roads: |
| 129 | for y in range(HEIGHT - 1, -1, -1): |
| 130 | # Print the street names on the left edge: |
| 131 | print(y, getOrdIndicator(y), ' St ', sep='', end='') |
| 132 | for x in range(WIDTH): |
| 133 | if x == playerx and y == playery: |
| 134 | print('X', end='') # Print the player location. |
| 135 | elif (x, y) in visitedIntersections: |
| 136 | print('O', end='') # Print a visited intersection. |
| 137 | else: |
| 138 | print(CROSS, end='') # Print an unvisited intersection. |
| 139 | |
| 140 | # Print the horizontal street segment: |
| 141 | if x < WIDTH - 1: |
| 142 | print(LEFTRIGHT * 3, end='') |
| 143 | |
| 144 | # Print the compass rose in the lower right corner: |
| 145 | if y == 1: |
| 146 | print(' N') |
| 147 | elif y == 0: |
| 148 | print(' S') |
| 149 | else: |
| 150 | print() # Just print a newline. |
| 151 | |
| 152 | # Print the vertical avenue segment. |
| 153 | if y > 0: |
| 154 | for x in range(WIDTH - 1): |
| 155 | if x == 0: |
| 156 | print(' ', end='') # Print indentation. |
| 157 | print(UPDOWN + ' ', end='') # Print an avenue segment. |
| 158 | print(UPDOWN, end='') # Print the rightmost avenue segment. |
| 159 | |
| 160 | # Print the compass rose in the lower right corner: |
| 161 | if y == 1: |
| 162 | print(' W' + LEFTRIGHT + CROSS + LEFTRIGHT + 'E') |
| 163 | elif y != 0: |
| 164 | print() # Just print a newline. |
| 165 | |
| 166 | |
| 167 | def askForPlayerMove(playerx, playery): |
no test coverage detected