"""Maze 3D, by Al Sweigart al@inventwithpython.com
Move around a maze and try to escape... in 3D!
This code is available at https://nostarch.com/big-book-small-python-programming
Tags: extra-large, artistic, maze, game"""
import copy, sys, os
# Set up the constants:
WALL = '#'
1 EMPTY = ' '
1 START = 'S'
1 EXIT = 'E'
1 BLOCK = chr(9617) # Character 9617 is '░'
1 NORTH = 'NORTH'
1 SOUTH = 'SOUTH'
1 EAST = 'EAST'
1 WEST = 'WEST'
1
1
2 def wallStrToWallDict(wallStr):
2 """Takes a string representation of a wall drawing (like those in
2 ALL_OPEN or CLOSED) and returns a representation in a dictionary
2 with (x, y) tuples as keys and single-character strings of the
2 character to draw at that x, y location."""
2 wallDict = {}
2 height = 0
2 width = 0
2 for y, line in enumerate(wallStr.splitlines()):
2 if y > height:
3 height = y
3 for x, character in enumerate(line):
3 if x > width:
3 width = x
3 wallDict[(x, y)] = character
3 wallDict['height'] = height + 1
3 wallDict['width'] = width + 1
3 return wallDict
3
3 EXIT_DICT = {(0, 0): 'E', (1, 0): 'X', (2, 0): 'I',
4 (3, 0): 'T', 'height': 1, 'width': 4}
4
4 # The way we create the strings to display is by converting the pictures
4 # in these multiline strings to dictionaries using wallStrToWallDict().
4 # Then we compose the wall for the player's location and direction by
4 # "pasting" the wall dictionaries in CLOSED on top of the wall diionary
4 # in ALL_OPEN.
4
4 ALL_OPEN = wallStrToWallDict(r'''
4 .................
5 ____.........____
5 ...|\......./|...
5 ...||.......||...
5 ...||__...__||...
5 ...||.|\./|.||...
5 ...||.|.X.|.||...
5 ...||.|/.\|.||...
5 ...||_/...\_||...
5 ...||.......||...
5 ___|/.......\|___
6 .................
6 .................'''.strip())
6 # The strip() call is used to remove the newline
6 # at the start of this multiline string.
6
6 CLOSED = {}
6 CLOSED['A'] = wallStrToWallDict(r'''
6 _____
6 .....
6 .....
7 .....
7 _____'''.strip()) # Paste to 6, 4.
7
7 CLOSED['B'] = wallStrToWallDict(r'''
7 .\.
7 ..\
7 ...
7 ...
7 ...
7 ../
8 ./.'''.strip()) # Paste to 4, 3.
8
8 CLOSED['C'] = wallStrToWallDict(r'''
8 ___________
8 ...........
8 ...........
8 ...........
8 ...........
8 ...........
8 ...........
9 ...........
9 ...........
9 ___________'''.strip()) # Paste to 3, 1.
9
9 CLOSED['D'] = wallStrToWallDict(r'''
9 ./.
9 /..
9 ...
9 ...
9 ...
10 \..
10 .\.'''.strip()) # Paste to 10, 3.
10
10 CLOSED['E'] = wallStrToWallDict(r'''
10 ..\..
10 ...\_
10 ....|
10 ....|
10 ....|
Do'stlaringiz bilan baham: |