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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
import random from draw_maze import * from maze_def import * from maze import *
def depth_maze_demo(levels, rows, cols): if 0 == levels % 2: levels+=1 if 0 == rows % 2: rows+=1 if 0 == cols % 2: cols+=1 maze_map = maze_init_draw(levels,rows,cols) nowx=1 nowy=1 nowz=0 history = [(nowx, nowy, nowz)] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: return if history: if maze_map[nowx][nowy][nowz] == CELL_NO_VISIT: maze_map[nowx][nowy][nowz] = NOWALL check = [] if nowx > 1 and maze_map[nowx-2][nowy][nowz] == CELL_NO_VISIT: check.append('L') if nowy > 1 and maze_map[nowx][nowy-2][nowz] == CELL_NO_VISIT: check.append('F') if nowx < cols-2 and maze_map[nowx+2][nowy][nowz] == CELL_NO_VISIT: check.append('R') if nowy < rows-2 and maze_map[nowx][nowy+2][nowz] == CELL_NO_VISIT: check.append('B') if nowz < levels-2 and maze_map[nowx][nowy][nowz+2] == CELL_NO_VISIT: check.append('U') if nowz > 1 and maze_map[nowx][nowy][nowz-2] == CELL_NO_VISIT: check.append('D') if len(check): history.append((nowx, nowy, nowz)) move_direction = random.choice(check) if move_direction == 'L': maze_map[nowx-1][nowy][nowz] = NOWALL maze_map[nowx-2][nowy][nowz] = NOWALL nowx=nowx-2 if move_direction == 'F': maze_map[nowx][nowy-1][nowz] = NOWALL maze_map[nowx][nowy-2][nowz] = NOWALL nowy=nowy-2 if move_direction == 'R': maze_map[nowx+1][nowy][nowz] = NOWALL maze_map[nowx+2][nowy][nowz] = NOWALL nowx=nowx+2 if move_direction == 'B': maze_map[nowx][nowy+1][nowz] = NOWALL maze_map[nowx][nowy+2][nowz] = NOWALL nowy=nowy+2 if move_direction == 'U': if maze_map[nowx][nowy][nowz] == STAIRS_D: maze_map[nowx][nowy][nowz] = STAIRS_UD else: maze_map[nowx][nowy][nowz] = STAIRS_U maze_map[nowx][nowy][nowz+1] = NOWALL if maze_map[nowx][nowy][nowz+2] == STAIRS_U: maze_map[nowx][nowy][nowz+2] = STAIRS_UD else: maze_map[nowx][nowy][nowz+2] = STAIRS_D nowz=nowz+2 if move_direction == 'D': if maze_map[nowx][nowy][nowz] == STAIRS_U: maze_map[nowx][nowy][nowz] = STAIRS_UD else: maze_map[nowx][nowy][nowz] = STAIRS_D maze_map[nowx][nowy][nowz-1] = NOWALL if maze_map[nowx][nowy][nowz-2] == STAIRS_D: maze_map[nowx][nowy][nowz-2] = STAIRS_UD else: maze_map[nowx][nowy][nowz-2] = STAIRS_U nowz=nowz-2 else: nowx, nowy, nowz = history.pop() draw_maze(maze_map, levels, rows, cols, (nowx,nowy,nowz), not history) time_passed = clock.tick(30)
pygame.display.update() return
if __name__ == "__main__": '''main''' depth_maze_demo(5, 11, 21)
|