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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
import pygame from maze import *
title = '火苗999℃' blog = '火苗999℃的博客' www='www.alom.com.cn'
pygame.init() size = width, height = 1024, 768 screen = pygame.display.set_mode(size) pygame.display.set_caption(blog)
diamond_color_size = 8 COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_YELLOW, COLOR_BLACK, COLOR_GRAY, COLOR_GOLDEN, COLOR_NO_DIAMOND = list(range( diamond_color_size)) COLOR = { COLOR_RED: (255, 0, 0), COLOR_BLUE: (0, 0, 255), COLOR_GREEN: (0, 255, 0), COLOR_YELLOW: (255, 255, 0), COLOR_BLACK: (0, 0, 0), COLOR_GRAY: (250, 240, 230), COLOR_GOLDEN : (255,215,0), COLOR_NO_DIAMOND: (160, 160, 160), }
DIAMOND_LENGTH = 12
DIAMOND_SIZE = (DIAMOND_LENGTH, DIAMOND_LENGTH)
use_font = pygame.font.Font("FONT.TTF", 16)
background=pygame.surface.Surface(size).convert() background.fill(COLOR[COLOR_NO_DIAMOND])
COLOR_U = (255,128,0) COLOR_D = (0x64,0x21,0x00) COLOR_W = (0xd9, 0x46, 0x00) COLOR_FONT=COLOR[COLOR_BLACK]
DIAMOND_U=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_U.fill(COLOR_W) pygame.draw.polygon(DIAMOND_U, COLOR_U, ((0,DIAMOND_LENGTH-1),(DIAMOND_LENGTH//2,0),(DIAMOND_LENGTH-1,DIAMOND_LENGTH-1))) surface_u = use_font.render("向上楼梯", True, COLOR_FONT)
DIAMOND_D=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_D.fill(COLOR_W) pygame.draw.polygon(DIAMOND_D, COLOR_D, ((0,0),(DIAMOND_LENGTH-1,0),(DIAMOND_LENGTH//2,DIAMOND_LENGTH-1))) surface_d = use_font.render("向下楼梯", True, COLOR_FONT)
DIAMOND_UD=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_UD.fill(COLOR_W) pygame.draw.polygon(DIAMOND_UD, COLOR_D, ((0,0),(DIAMOND_LENGTH-1,0),(DIAMOND_LENGTH//2,DIAMOND_LENGTH//2))) pygame.draw.polygon(DIAMOND_UD, COLOR_U, ((0,DIAMOND_LENGTH-1),(DIAMOND_LENGTH//2,DIAMOND_LENGTH//2+1),(DIAMOND_LENGTH-1,DIAMOND_LENGTH-1))) surface_ud = use_font.render("上下楼梯", True, COLOR_FONT)
DIAMOND_W=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_W.fill(COLOR_W)
DIAMOND_GRAY=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_GRAY.fill(COLOR[COLOR_GRAY])
DIAMOND_RED=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_RED.fill(COLOR[COLOR_RED])
DIAMOND_YELLOW=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_YELLOW.fill(COLOR[COLOR_YELLOW])
DIAMOND_NO_VISIT=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_NO_VISIT.fill(COLOR[COLOR_BLACK]) surface_nv = use_font.render("未访问的格式", True, COLOR_FONT)
DIAMOND_WALL_NO_VISIT=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_WALL_NO_VISIT.fill(COLOR[COLOR_GOLDEN]) surface_wnv = use_font.render("未访问的墙", True, COLOR_FONT)
DIAMOND_VISIT=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_VISIT.fill(COLOR[COLOR_GREEN]) DIAMOND_VISIT=DIAMOND_W surface_v = use_font.render("访问过的格式或打通的墙", True, COLOR_FONT)
DIAMOND_O=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_O.fill((255,128,0)) DIAMOND_G=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_G.fill((0,102,51)) DIAMOND_R=pygame.surface.Surface(DIAMOND_SIZE).convert() DIAMOND_R.fill((102,0,0))
clock = pygame.time.Clock()
def draw_maze(maze_map, levels, rows, cols, point, over): screen.blit(background, (0, 0)) for zi in range(levels): for xi in range(cols): for yi in range(rows): a = zi % 2 b = zi // 2 px, py = 1 + xi * DIAMOND_SIZE[0] + a * (cols*DIAMOND_LENGTH+10), 1 + yi * DIAMOND_SIZE[1] + b*(rows*DIAMOND_LENGTH+10) if CELL_NO_VISIT == maze_map[xi][yi][zi]: screen.blit(DIAMOND_NO_VISIT, (px, py)) elif WALL_NO_VISIT == maze_map[xi][yi][zi]: screen.blit(DIAMOND_WALL_NO_VISIT, (px, py)) elif STEEL == maze_map[xi][yi][zi]: screen.blit(DIAMOND_GRAY, (px, py)) elif WALL_VISIT == maze_map[xi][yi][zi]: screen.blit(DIAMOND_GRAY, (px, py)) elif NOWALL & maze_map[xi][yi][zi]: screen.blit(DIAMOND_W, (px, py)) elif STAIRS_UD == (STAIRS_UD & maze_map[xi][yi][zi]): screen.blit(DIAMOND_UD, (px, py)) elif STAIRS_U & maze_map[xi][yi][zi]: screen.blit(DIAMOND_U, (px, py)) elif STAIRS_D & maze_map[xi][yi][zi]: screen.blit(DIAMOND_D, (px, py)) elif CELL_VISIT & maze_map[xi][yi][zi]: screen.blit(DIAMOND_W, (px, py)) elif WALL & maze_map[xi][yi][zi]: screen.blit(DIAMOND_GRAY, (px, py)) else: screen.blit(DIAMOND_YELLOW, (px, py))
if not over: a = point[2] % 2 b = point[2] // 2 px, py = 1 + point[0] * DIAMOND_SIZE[0] + a * (cols*DIAMOND_LENGTH+10), 1 + point[1] * DIAMOND_SIZE[1] + b*(rows*DIAMOND_LENGTH+10) screen.blit(DIAMOND_RED, (px, py)) posx,posy = 20, ((levels + 1) // 2)*(rows*DIAMOND_LENGTH+10) screen.blit(DIAMOND_U, (posx, posy)) screen.blit(DIAMOND_D, (posx, posy+20)) screen.blit(DIAMOND_UD, (posx, posy+40)) screen.blit(DIAMOND_NO_VISIT, (posx, posy+60)) screen.blit(DIAMOND_WALL_NO_VISIT, (posx, posy+80)) screen.blit(DIAMOND_VISIT, (posx, posy+100)) screen.blit(surface_u, (posx+20, posy)) screen.blit(surface_d, (posx+20, posy+20)) screen.blit(surface_ud, (posx+20, posy+40)) screen.blit(surface_nv, (posx+20, posy+60)) screen.blit(surface_wnv, (posx+20, posy+80)) screen.blit(surface_v, (posx+20, posy+100))
if over: score_surface = use_font.render("生成完成! by " + title, True, COLOR_FONT, COLOR[COLOR_GRAY]) screen.blit(score_surface, (posx+20, posy+120)) return
|