def userinput(): global menuactive global question global pet while True: # waitingoninput = input("") # if waitingoninput == "m" or waitingoninput == "M": # menuitems = ['Feed', 'Play', 'Sleep', 'Exit'] gui.menu(pet)
def main_menu(): libtcod.console_set_custom_font( 'terminal8x12_gs_ro.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT, 'Monster Genetics', False) libtcod.sys_set_fps(cfg.LIMIT_FPS) img = libtcod.image_load('menu_background.png') while not libtcod.console_is_window_closed(): gui.display_main_menu(img) #show options and wait for the player's choice choice = gui.menu('', [ 'Play a new game', 'Continue last game', 'Display controls', 'Quit' ], 24) if choice == 0: #new game new_game() play_game() elif choice == 1: #load last game try: load_game() except: gui.msgbox('\n No saved game to load.\n', 24) continue play_game() elif choice == 2: #controls, will eventually be options menu gui.display_controls() elif choice == 3: #quit break
def tame_animal(parameters, source=None, target=None): source=defn.player if parameters['target type']=='none': pass #eventually, maybe we can upgrade so that everything in sight is converted. elif parameters['target type']=='creature': #find target. currently geared to ranged attacks, though can easily be extended to melee target = spfn.target_monster(parameters['range']) if target: if target.creature.alignment == 'dungeon' and 'animal' in target.properties['subtypes']: if defn.player.properties['level'] > target.properties['level']: health_percentage = float(target.creature.hp) / float(target.creature.max_hp) if health_percentage <= parameters['threshold'] or target.creature.hp == 1: target.creature.alignment = 'player' target.color = libtcod.white gui.message('The ' + target.name + ' submits to your will!', libtcod.green) choice = gui.menu('Name your new friend?', ['Yes', 'No'], 24) if choice == 0: #give it a name name = itxt.input_text(50, 5, 'What would you like to name it?\n\n', '\n\n(Press *ENTER* when done)') target.personal_name = name return 'succeeded' else: gui.message('The ' + target.name + ' resists your attempts to tame it.', libtcod.red) return 'failed' gui.message('You are not experienced enough to tame that.', libtcod.white) return 'cancelled' gui.message('You cannot tame that!', libtcod.white) return 'cancelled' else: return 'cancelled'
def menu_cfg(msg): '''Exibe um diálogo com opções para procurar e copiar um arquivo de configuração do d10r, criar um novo arquivo e sair do programa.''' botoes = ('Novo', 'Procurar', 'Sair') data.CONFIG msg += ''' O que deseja fazer? %s: Criar um novo arquivo %s: Utilizar um outro arquivo %s: Sair do programa''' % tuple(botoes) botao = gui.menu(msg, botoes) if botao == botoes[0]: init() elif botao == botoes[1]: caminho = gui.escolher_arquivo('Escolha o arquivo desejado', 'cfg') if caminho: if gui.perguntar( 'O arquivo selecionado está fora do local padrão, ' + 'de forma que o programa sempre perguntará por ele ' + 'quando iniciar. Deseja copiar o arquivo para o local ' + 'padrão?\n\nSe sim, você precisará fazer backup do arquivo ' + 'sempre que for utilizá-lo em outro computador.'): shutil.copy2(caminho, data.CONFIG) gui.notificar('Arquivo copiado com sucesso!') else: data.CONFIG = caminho else: gui.notificar('Preciso do arquivo de configuração para continuar!') else: raise SystemExit(0)
def check_level_up(): #see if the player's experience is enough to level-up level_up_xp = defn.LEVEL_UP_BASE + defn.player.properties[ 'level'] * defn.LEVEL_UP_FACTOR if defn.player.creature.xp >= level_up_xp: #it is! level up defn.player.properties['level'] += 1 defn.player.creature.xp -= level_up_xp gui.message( 'You reached level ' + str(defn.player.properties['level']) + '!', libtcod.yellow) choice = None while choice == None: #keep asking until a choice is made choice = gui.menu('Level up! Choose a stat to raise:\n', [ '+4 Life, from ' + str(defn.player.creature.base_max_hp), '+5 Mana Capacity, from ' + str(defn.player.creature.base_max_mana), '+1 Channeling, from ' + str(defn.player.creature.channeling) ], defn.LEVEL_SCREEN_WIDTH) if choice == 0: defn.player.creature.base_max_hp += 4 defn.player.creature.hp += 4 elif choice == 1: defn.player.creature.base_max_mana += 5 defn.player.creature.mana += 5 elif choice == 2: defn.player.creature.channeling += 1
def menu_cfg(msg): '''Exibe um diálogo com opções para procurar e copiar um arquivo de configuração do d10r, criar um novo arquivo e sair do programa.''' botoes = ('Novo', 'Procurar', 'Sair') data.CONFIG msg += ''' O que deseja fazer? %s: Criar um novo arquivo %s: Utilizar um outro arquivo %s: Sair do programa''' % tuple(botoes) botao = gui.menu(msg, botoes) if botao == botoes[0]: init() elif botao == botoes[1]: caminho = gui.escolher_arquivo('Escolha o arquivo desejado', 'cfg') if caminho: if gui.perguntar('O arquivo selecionado está fora do local padrão, ' + 'de forma que o programa sempre perguntará por ele ' + 'quando iniciar. Deseja copiar o arquivo para o local ' + 'padrão?\n\nSe sim, você precisará fazer backup do arquivo ' + 'sempre que for utilizá-lo em outro computador.'): shutil.copy2(caminho, data.CONFIG) gui.notificar('Arquivo copiado com sucesso!') else: data.CONFIG = caminho else: gui.notificar('Preciso do arquivo de configuração para continuar!') else: raise SystemExit(0)
def spellbook_menu(header): spellbook = defn.player.spellbook contents = spellbook.contents #will implement cantrips later. #show a menu with each spell in memory as an option if len(contents) == 0: options = ['You don\'t know any spells.'] else: options = [] #show spell names and mana costs. Indent properly so that all spells are aligned. for entry in contents: quantity = entry[1] spell = entry[0] if quantity == 'infinite': text = ' ' + spell.name.capitalize() + ' (' + str( spell.cost) + ')' elif spellbook.get_quantity(spell) < 10: text = str(quantity) + ' ' + spell.name.capitalize( ) + ' (' + str(spell.cost) + ')' elif spellbook.get_quantity(spell) < 100: text = str(quantity) + ' ' + spell.name.capitalize( ) + ' (' + str(spell.cost) + ')' options.append(text) index = gui.menu(header, options, defn.SPELLBOOK_WIDTH) #if a spell was chosen, return it if index is None or len(contents) == 0: return None if spellbook.get_quantity(spellbook.get_item_at_position(index)) == 0: return None return spellbook.get_item_at_position(index)
def create_character(): #Choose a name for your character gui.clear_screen() name = input_text.input_text(50, 5, 'What is your name?\n\n', '\n\n(press *Enter* when done to continue)') gui.clear_screen() #Choose your mage class index = gui.menu('What sort of mage are you?', mgdic.mages, defn.SCHOOLS_WIDTH) mage = mgdic.mage_dict[mgdic.mages[index]] #Create player object mgdic.create_player(mage, 0, 0) defn.player.name = name
def debitar(atividade, parar=True): c = 'Cronômetro' op = gui.menu('Deseja iniciar o cronômetro ou inserir a quantidade ' + 'de horas cumpridas diretamente?', (c, 'Inserir')) if op == c: return gui.cronometro_dialog(atividade, parar) else: try: h, m, s = gui.horaspin('Atividade: %s' % atividade.nome) h += (m / 60.0) + (s / 3600.0) return h except TypeError: return 0.0
def debitar(atividade, parar=True): c = 'Cronômetro' op = gui.menu( 'Deseja iniciar o cronômetro ou inserir a quantidade ' + 'de horas cumpridas diretamente?', (c, 'Inserir')) if op == c: return gui.cronometro_dialog(atividade, parar) else: try: h, m, s = gui.horaspin('Atividade: %s' % atividade.nome) h += (m / 60.0) + (s / 3600.0) return h except TypeError: return 0.0
def summoning_menu(header): #show a menu with each creature as an option if len(defn.inventory) == 0: options = ['No allies to summon.'] else: options = [] for obj in defn.player.creatures: text = obj.title #show additional information, in case it's equipped options.append(text) index = gui.menu(header, options, defn.INVENTORY_WIDTH) #if an item was chosen, return it if index is None or len(defn.player.creatures) == 0: return None return defn.player.creatures[index]
def inventory_menu(header): #show a menu with each item of the inventory as an option if len(defn.inventory) == 0: options = ['Inventory is empty.'] else: options = [] for item in defn.inventory: text = item.properties['graphic'] + ' ' + item.properties['name'] #show additional information, in case it's equipped if item.equipment and item.equipment.is_equipped: text = text + ' (on ' + item.equipment.slot + ')' options.append(text) index = gui.menu(header, options, defn.INVENTORY_WIDTH) #if an item was chosen, return it if index is None or len(defn.inventory) == 0: return None return defn.inventory[index].item
def main(): global DISPLAYSURF, TITLEFONT, SUBTITLEFONT, BUTTONFONT, CLOCK pygame.init() pygame.font.init() CLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) TITLEFONT = pygame.font.Font(None, 110) SUBTITLEFONT = pygame.font.Font(None, 100) BUTTONFONT = pygame.font.Font(None, 90) TEXTFONT = pygame.font.Font(None, 25) pygame.display.set_caption("Chaos Simulator") exec( gui.menu(DISPLAYSURF, (TITLEFONT, BUTTONFONT), "CHAOS SIMULATOR", [["Start", ["start_menu()"]], ["Quit", ["pygame.quit()", "sys.exit()"]]]))
def main_menu(): img = libtcod.image_load(random.choice(defn.title_screen_choices)) while not libtcod.console_is_window_closed(): #show the background image, at twice the regular console resolution libtcod.image_blit_2x(img, 0, 0, 0) #show the game's title, and some credits! libtcod.console_set_default_foreground(0, libtcod.light_yellow) libtcod.console_print_ex(0, defn.SCREEN_WIDTH / 2, defn.SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'Mage Wars RL') libtcod.console_print_ex(0, defn.SCREEN_WIDTH / 2, defn.SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'A Roguelike Adventure by ACG') #show options and wait for the player's choice choice = gui.menu('', ['Play a new game', 'Continue last game', 'Quit'], 24) if choice == 0: #new game new_game.new_game() game.play_game() if choice == 1: #load last game gui.msgbox( '\n Sorry - I haven\'nt implemented a save/load feature yet.\n\n-ACG\n', 24) #try: # load_game() #except: # msgbox('\n No saved game to load.\n', 24) # continue #game.play_game() elif choice == 2: #quit break
def settings(): #global dotColour, dotSize, dotNumber, dotList exec( gui.menu(DISPLAYSURF, (TITLEFONT, BUTTONFONT), "fa", ["start", ["start()"]]))
def start_menu(): exec( gui.menu(DISPLAYSURF, (TITLEFONT, BUTTONFONT), "Chaos", [["Start", ["start()"]], ["Settings", ["settings()"]]]))
def main(): single_player = menu(WIN) print(single_player) while True: init_game(WIN, single_player)