def update(self, selected): for y in self.composition: for x in self.composition[y]: console.setColorXY( x, y, self.composition[y][x], self.colorForeSelected | self.colorBackSelected if selected else self.colorForeUnselected | self.colorBackUnselected) if selected and not self.selectFunction is None: self.selectFunction()
def instructions(): global gui if not gui == None: gui.stop() console.clear() banner = [ " ", " ", "###", " # # # ### ### # ## # # ## ## ## ###", " # ## # ## # ## # # # # # #### ##", " # # ## ## # # # # # # # # ##", "### # # ### # # ### ## ## ## ###" ] for yBanner in range(0, len(banner)): for xBanner in range(0, len(banner[yBanner])): text = banner[yBanner][xBanner] if text == '#': console.setColorXY( xBanner + int(SCREEN_COLUMNS / 6), yBanner, ' ', Colors.BACKGROUND_YELLOW | Colors.BACKGROUND_BOLD) console.setColor(Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) gui = GUI(len(banner) + 16, 0) gui.addButton(len(banner) + 5, 0, GUIButton('1', [" Instruções:"])) gui.addButton( len(banner) + 7, 0, GUIButton('2', [" W = Mover para cima"])) gui.addButton( len(banner) + 8, 0, GUIButton('3', [" S = Mover para baixo"])) gui.addButton( len(banner) + 9, 0, GUIButton('4', [" A = Mover para esquerda"])) gui.addButton( len(banner) + 10, 0, GUIButton('5', [" D = Mover para direita"])) gui.addButton( len(banner) + 11, 0, GUIButton('6', [" (ou, utilize as setas)"])) gui.addButton( len(banner) + 13, 0, GUIButton('7', [ " * Seu objetivo é encontrar a saída do labirinto (ponto VERDE)" ])) gui.addButton( len(banner) + 14, 0, GUIButton('8', [ " dentro do tempo limite, para assim, liberar a próxima fase!" ])) gui.addButton( len(banner) + 16, 0, GUIButton("Voltar", [" < Voltar ao menu"], lambda: back(), None, Colors.FOREGROUND_WHITE, Colors.FOREGROUND_BLACK, Colors.BACKGROUND_RED, Colors.BACKGROUND_RED)) gui.display()
def run_menu(): try: system('mode con: cols={} lines={}'.format(SCREEN_COLUMNS, SCREEN_LINES)) banner = [ " ", " ", " ", " ", " ", "# ", "# ##### # # # ## # ### # # # ####", "# # # ### ## # # ### ### # #", "# # # # # # # # # # # # # ######", "# # # # # # # # # # # # # #", "#### ##### ### # # # # # ## # ## ####" ] spacer = int(SCREEN_COLUMNS / 5) for yBanner in range(0, len(banner)): for xBanner in range(0, len(banner[yBanner])): text = banner[yBanner][xBanner] if text == '#': console.setColorXY( xBanner + spacer, yBanner, ' ', Colors.BACKGROUND_YELLOW | Colors.BACKGROUND_BOLD) console.setColorXY(spacer, len(banner) + 3, " Criado por Willian Gois & Lucas Verona", Colors.FOREGROUND_YELLOW) global gui gui = GUI(20, int(SCREEN_LINES / 2)) gui.addButton( 20, int(SCREEN_LINES / 2), GUIButton("Jogar", [" ", " Jogar ", " "], lambda: play())) gui.addButton( 20, int(SCREEN_LINES / 1), GUIButton("Editor de Mapas", [ " ", " Editor de Mapa ", " " ], lambda: run_map_editor())) gui.addButton( 20, int(SCREEN_LINES / 0.65), GUIButton("Instruções", [" ", " Instrucoes ", " "], lambda: instructions())) gui.display() except Exception as e: print("ERRO GERAL: ", e) sleep(1000)
def select_map(map): global SELECTED_HEIGHT global SELECTED_WIDTH global gui spacerY = len(gui.buttons) + 3 spacerX = 5 for selY in range(spacerY, spacerY + SELECTED_HEIGHT): for selX in range(spacerX, spacerX + SELECTED_WIDTH): console.setColorXY(selX, selY, ' ', Colors.FOREGROUND_WHITE | Colors.BACKGROUND_BLACK) for editMessageX in range(0, len("Clique para editar!")): console.setColorXY(spacerX + editMessageX, spacerY - 2, " ", Colors.FOREGROUND_WHITE | Colors.BACKGROUND_BLACK) if not map == None: for y in map.composition: for x in map.composition[y]: console.setColorXY(int(x) + spacerX, int(y) + spacerY, map.composition[y][x], Colors.FOREGROUND_WHITE | Colors.BACKGROUND_BLACK) SELECTED_HEIGHT = map.height + 2 #Números não precísos pois a altura pode variar um pouco pra cima/baixo por conta do algorítmo de geração automática SELECTED_WIDTH = map.width * 2 + spacerX #Números não precísos pois a largura pode variar um pouco pra cima/baixo por conta do algorítmo de geração automática console.setColorXY(spacerX, spacerY - 2, "Clique para editar!", Colors.FOREGROUND_WHITE | Colors.BACKGROUND_BLACK)
def confirm(gui): global CREATING_MAP_NAME if not get_map_by_name(CREATING_MAP_NAME) is None: console.setColorXY(5, len(MAPS) + 20, " >> Já existe um mapa com esse nome...", Colors.BACKGROUND_RED | Colors.FOREGROUND_WHITE) else: global CREATING_MAP_HEIGHT global CREATING_MAP_WIDTH global CREATING_MAP_TIME global CREATING_MAP_AUTO_GENERATION if CREATING_MAP_HEIGHT == "" or CREATING_MAP_WIDTH == "" or CREATING_MAP_TIME == "" or CREATING_MAP_AUTO_GENERATION == "": console.setColorXY(5, len(MAPS) + 20, " >> Um dos campos não foi preenchido...", Colors.BACKGROUND_RED | Colors.FOREGROUND_WHITE) elif not CREATING_MAP_HEIGHT.isdigit() or not CREATING_MAP_WIDTH.isdigit() or not CREATING_MAP_TIME.isdigit(): console.setColorXY(5, len(MAPS) + 20, " >> O valor do campo Altura, Largura ou o Tempo não é um número válido...", Colors.BACKGROUND_RED | Colors.FOREGROUND_WHITE) else: composition = {} if CREATING_MAP_AUTO_GENERATION == "SIM": composition = generate_composition(int(CREATING_MAP_HEIGHT), int(CREATING_MAP_WIDTH)) else: for y in range(0, int(CREATING_MAP_HEIGHT)): composition[y] = {} for x in range(0, int(CREATING_MAP_WIDTH)): if y == 0 or y == int(CREATING_MAP_HEIGHT) - 1 or x == 0 or x == int(CREATING_MAP_WIDTH) - 1: composition[y][x] = WALL else: composition[y][x] = SPACE map = Map(CREATING_MAP_NAME, len(MAPS) + 1, int(CREATING_MAP_TIME), int(CREATING_MAP_HEIGHT), int(CREATING_MAP_WIDTH), composition) map.save() MAPS.append(map) console.setColorXY(5, len(MAPS) + 20, " >> Mapa criado com sucesso!", Colors.BACKGROUND_GREEN | Colors.FOREGROUND_WHITE) sleep(3) gui.stop() del gui console.clear() run_editor()
def verifyAutoGeneration(buttonY, buttonX): for x in range(buttonX, buttonX + 10): console.setXY(x, buttonY, ' ') global CREATING_MAP_AUTO_GENERATION if CREATING_MAP_AUTO_GENERATION == "NAO": console.setColorXY(buttonX + 1, buttonY, "SIM / ", Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) console.setColorXY(buttonX + 7, buttonY, "NAO", Colors.BACKGROUND_RED) else: console.setColorXY(buttonX + 1 , buttonY, "SIM", Colors.BACKGROUND_GREEN) console.setColorXY(buttonX + 4, buttonY, " / NAO", Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) option = "SIM" while True: keyword = str(console.getKeyword()) if keyword == 'right' or keyword == 'd': option = "NAO" console.setColorXY(buttonX + 1, buttonY, "SIM / ", Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) console.setColorXY(buttonX + 7, buttonY, "NAO", Colors.BACKGROUND_RED) elif keyword == 'left' or keyword == 'a': option = "SIM" console.setColorXY(buttonX + 1, buttonY, "SIM", Colors.BACKGROUND_GREEN) console.setColorXY(buttonX + 4, buttonY, " / NAO", Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) elif keyword == 'enter': for x in range(buttonX, buttonX + 10): console.setColorXY(x, buttonY, ' ', Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) CREATING_MAP_AUTO_GENERATION = option create_map() break
def play(): global gui if not gui == None: gui.stop() console.clear() banner = [ " ", " ", " ### ###", "# ## # ## ## # ## # # ### # # # ### ### ##", " ### #### # #### # # # ## # # # ## ## # # ## ####", " # # # # # # # # # ## # # # # # # ## #", " ### ## ### ## ## # ## # # ### # # ### ### ##" ] for yBanner in range(0, len(banner)): for xBanner in range(0, len(banner[yBanner])): text = banner[yBanner][xBanner] if text == '#': console.setColorXY( xBanner + int(SCREEN_COLUMNS / 6), yBanner, ' ', Colors.BACKGROUND_YELLOW | Colors.BACKGROUND_BOLD) console.setColor(Colors.BACKGROUND_BLACK | Colors.FOREGROUND_WHITE) data.load_data() map_editor.load_maps() gui = GUI(10, 0) for mapIndex in range(0, len(map_editor.MAPS)): map = map_editor.MAPS[mapIndex] if data.playerData.isLocked(map): gui.addButton( mapIndex + 10, 0, GUIButton(map.name, [" ?. ????? Melhor tempo: --:--"], partial(play_map, map), colorBackSelected=Colors.BACKGROUND_RED, colorForeSelected=Colors.FOREGROUND_WHITE)) else: timeString = "" if data.playerData.times[str(map.level)] == -1: timeString = "--:--" else: seconds = map.timeCounter - data.playerData.times[str( map.level)] minutes = 0 while seconds >= 60: seconds -= 60 minutes += 1 timeString = str(minutes) + ":" + str(seconds) gui.addButton( mapIndex + 10, 0, GUIButton(map.name, [ " " + str(mapIndex + 1) + ". " + map.name + " Melhor tempo: " + timeString ], partial(play_map, map))) gui.addButton( len(map_editor.MAPS) + 11, 0, GUIButton("Voltar", [" < Voltar ao menu"], lambda: back(), None, Colors.FOREGROUND_WHITE, Colors.FOREGROUND_BLACK, Colors.BACKGROUND_RED, Colors.BACKGROUND_RED)) gui.display()