def run(): """运行游戏""" # load setting first background = func.hex_to_rgb(func.setting["color"]["background"]) level = func.setting["level"] screenSize = (func.size * 50, func.size * 50) # 创建屏幕对象 pygame.init() screen = pygame.display.set_mode(screenSize) pygame.display.set_caption("Minesweeper") board = getBoard(level) print("Initial Board") func.printBoard(board) while True: checkEvents(board, screen) updateScreen(background, screen, board) status = func.isEnd(board, func.size * level) if status[0]: time.sleep(1) print("End Board") func.printBoard(board) displayEndBoard(background, screen, status[1])
def displayEndBoard(background, screen, statement): player = func.setting["player"] textFont = func.setting["font"]["text_font"] textColor = func.hex_to_rgb(func.setting["color"]["text"]) # alerting text fontTitle = pygame.font.SysFont(textFont, 90) # (字体,大小) title = 'Game End' text_title = fontTitle.render(title, True, textColor) titleRect = text_title.get_rect() titleRect.center = (225, 175) # status text fontSentence = pygame.font.SysFont(textFont, 40) # (字体,大小) sentence = player + ", you " + statement text_sentence = fontSentence.render(sentence, True, textColor) sentenceRect = text_sentence.get_rect() sentenceRect.center = (225, 300) # display them while True: screen.fill(background) screen.blit(text_title, titleRect) screen.blit(text_sentence, sentenceRect) pygame.display.flip() checkEvent(screen)
def render_tile(location): # Connect to Redis and Blockchain redis_server = connect_redis() contract = get_contract() # Get Tile Data try: tile = contract.call().getTile(location) except: print "Can't connect to Parity, or !synced to block #2641527. Waiting \ 5 seconds..." tile = False while not tile: try: tile = contract.call().getTile(location) except: time.sleep(5) print "Can't connect to Parity, or !synced to block #2641527. \ Waiting 5 seconds..." tile = False owner = tile[0] url = tile[2] image = tile[1] price = tile[3] tile_name = str(location) print "Rendering " + tile_name + "..." # Defaults if data not set. if not url: url = get_default_url() if not image: image = get_default_tile(owner) if (price != 0): image = get_for_sale_tile() # Update Redis Data redis_server.hmset(tile_name, {'owner': owner, 'url': url}) # Render Image from Image Data. Every 3 char. represents 1 pixel. rgb_image_data = [] for pixel in chunk_str(image, 3): rgb_image_data.append(hex_to_rgb(double_mult(pixel))) # Start with Black Image rendered_image = Image.new('RGB', (16, 16), "black") pixels = rendered_image.load() # For every pixel in image: for i in range(rendered_image.size[0]): for j in range(rendered_image.size[1]): pixel = rgb_image_data[get_position(i, j)] pixels[i, j] = (pixel[0], pixel[1], pixel[2]) # Save Tile rendered_image.save('tiles/' + tile_name + ".png")
def render_tile(location): # Connect to Redis and Blockchain redis_server = connect_redis() contract = get_contract() # Get Tile Data try: tile = contract.functions.tiles(location).call() except Exception as e: print(e) print( "Can't connect to Parity, or !synced to block #2641527. Waiting 5 seconds..." ) tile = False while not tile: try: tile = contract.functions.tiles(location).call() except Exception as e: time.sleep(5) print("Can't connect to Parity, or !synced to block #2641527. \ Waiting 5 seconds...") print(e) tile = False owner = tile[0] url = tile[2] image = tile[1] price = tile[3] tile_name = str(location) print("Rendering " + tile_name + "...") # Defaults if data not set. if not url: url = get_default_url() if not image: image = get_default_tile(owner) image = image.strip() if not len(image) == 768: image = get_default_tile(owner) if price != 0: image = get_for_sale_tile() # Update Redis Data redis_server.hmset(tile_name, {"owner": owner, "url": url}) # Render Image from Image Data. Every 3 char. represents 1 pixel. rgb_image_data = [] for pixel in chunk_str(image, 3): rgb_image_data.append(hex_to_rgb(double_mult(pixel))) # Start with Black Image rendered_image = Image.new("RGB", (16, 16), "black") pixels = rendered_image.load() # For every pixel in image: for i in range(rendered_image.size[0]): for j in range(rendered_image.size[1]): pixel = rgb_image_data[get_position(i, j)] pixels[i, j] = (pixel[0], pixel[1], pixel[2]) # Save Tile rendered_image.save("tiles/" + tile_name + ".png") # Make big tile for OpenSea big_tile = rendered_image.resize((350, 350), Image.NEAREST) big_tile.save("large_tiles/" + tile_name + ".png") data = { "description": "Official PixelMap (2016) Wrapper", "external_url": url, "image": f"https://s3.us-east-1.amazonaws.com/pixelmap.io/{tile_name}.png", "name": f"Tile #{tile_name}", } with open(f"large_tiles/{tile_name}.json", "w") as outfile: json.dump(data, outfile, indent=4)