예제 #1
0
def main():
    while True:
        clear_screen()
        ui.menu()
        user_choice = int(input())
        if user_choice == 1:
            ui.how_to_play()
        elif user_choice == 2:
            play_game()
        elif user_choice == 3:
            ui.high_scores()
        elif user_choice == 4:
            sys.exit(4)
        else:
            raise ValueError("There is no such option")
예제 #2
0
def start_conversation(target, actor):
    if target.npc is None:
        raise Exception('Tried to talk to non npc')

    npc = target.npc
    state = npc.dialog[npc.dialog_root]
    if state.get('event') is not None and callable(state['event']):
        state['event']()

    while state != 'end_conversation' and state is not None:
        if callable(state):
            state = state()
        if isinstance(state, types.StringTypes):
            if state in npc.dialog:
                state = npc.dialog[state]
            else:
                break
        if isinstance(state, list) or isinstance(state, tuple):
            state = main.random_entry(state)
        else:
            keys = state['options'].keys()
            selection = ui.menu(target.name + '\n\n' + state['text'],
                                keys,
                                width=45)
            if selection is not None:
                state = state['options'][keys[selection]]
            else:
                break

    return 'success'
예제 #3
0
def forge():
    import loot
    choices = [
        i for i in player.instance.fighter.inventory
        if i.equipment is not None and i.equipment.category in forge_targets
    ]

    if len(choices) < 1:
        ui.message('You have no items to forge.', libtcod.orange)
        return 'didnt-take-turn'

    index = ui.menu('Forge what?', [c.name for c in choices])
    if index is None:
        ui.message('Cancelled.', libtcod.orange)
        return 'didnt-take-turn'
    target = choices[index].equipment

    if target.quality == 'artifact':
        ui.message(
            'Your ' + target.owner.name +
            ' shimmers briefly. It cannot be improved further by this magic.',
            libtcod.orange)
    elif target.category == 'weapon' and target.material == '':  #can't forge summoned weapons
        ui.message(
            'The %s cannot be altered by this magic.' % target.owner.name,
            libtcod.orange)
    else:
        ui.message('Your ' + target.owner.name + ' glows bright orange!',
                   libtcod.orange)

        index = loot.quality_progression.index(target.quality)
        new_quality = loot.quality_progression[index + 1]
        main.set_quality(target, new_quality)
        ui.message('It is now a ' + target.owner.name + '.', libtcod.orange)
    return True
예제 #4
0
def main():
    while True:
        rules = []
        rules = get_rules_from_file()
        user_is_smart = False
        print(rules)
        while user_is_smart == False:
            user_choose = menu()
            if user_choose == '1':
                content = make_content_from_file("random_like_init.txt")
            elif user_choose == '2':
                content = make_content_from_file("glider.txt")
            elif user_choose == '3':
                content = make_content_from_file("stable_configurations.txt")
            elif user_choose == '4':
                content = make_content_from_file("glider_gun.txt")
            elif user_choose == '5':
                filename = input("Insert path here:")
                content = make_content_from_file(filename)
            else:
                print('Think again!')
                continue
            user_is_smart = True

        display(content)
        input('Press enter to start!')
        run = True
        while run:
            try:
                display(content)
                time.sleep(.1)
                content = step(content, rules)
                clear()
            except KeyboardInterrupt:
                break
예제 #5
0
def main():
    click.clear()
    click.echo(f'{click.style("Twitter Hashtag Ranking", fg="blue")} - v1')
    print("Select the database that you want to work on, or write the name of a new one.")

    forbidden_names = ['local', 'admin', 'config']

    mongoclient = MongoClient(host=config['MONGODB']['Host'], port=int(config['MONGODB']['Port']),
                              username=config['MONGODB']['Username'], password=config['MONGODB']['Password'])
    db_list = [db for db in mongoclient.list_database_names() if db not in forbidden_names]
    mongoclient.close()

    for db in db_list:
        print("\t- " + db)

    db_name = click.prompt("\nEnter the name of an existing database or a new one", confirmation_prompt=True, type=str)
    mongoengine.connect(db=db_name, username=config['MONGODB']['Username'], password=config['MONGODB']['Password'],
                        authentication_source=config['MONGODB']['Authentication_Source'],
                        host=config['MONGODB']['Host'])

    ui.menu()
예제 #6
0
def essence_fist(actor, target, context):
    ops = player.instance.essence
    choice = ui.menu('Which essence?',ops)
    if choice is not None:
        essence = ops[choice]
    else:
        return "didnt-take-turn"

    result = combat.attack_ex(player.instance.fighter,target,context['stamina_cost'],damage_multiplier=context['damage_multiplier'])
    if result != 'failed':
        player.instance.essence.remove(essence)
        return result
예제 #7
0
def index(req):
    """ main test page """
    req.content_type = 'application/xhtml+xml'
    o = '<?xml version="1.0" encoding="UTF-8"?>\n'
    o += '<?xml-stylesheet href="%s" type="text/css"?>\n'%ui.__CSS__
    o += '<svg %s editable="yes" test="yes">\n'%ui._SVGNS
    o += '<title id=".title">Test</title>'
    o += '<link %s rel="shortcut icon" href="logo16.png"/>\n'%ui._XHTMLNS
    o += ui.include_ace('.')
    o += '<script %s type="text/ecmascript" xlink:href="xregexp-min.js"></script>\n'%ui._XLINKNS
    o += '<script %s type="text/ecmascript" xlink:href="%s"></script>\n'%(ui._XLINKNS,ui.__JS__)
    o += '<script %s type="text/ecmascript" xlink:href="test_client.js"></script>\n'%ui._XLINKNS
    o += '<foreignObject display="none" width="100%%" height="100%%"><div %s id=".editor" class="editor"></div></foreignObject>'%ui._XHTMLNS
    mygraph = ui.cg('')
    o += mygraph.draw() + ui.menu() + ui.gui_elements() + ui.menubar(req,'reload')
    o += '<g onclick="run_tests();"><rect x="160" width="70" height="18" fill="red" class="button"/><text y="12" x="166" class="button" fill="white">Run tests</text></g><g transform="translate(5,20)"><text id=".results" stroke-width="0"/></g>'
    o += '<g onclick="update_tool();"><rect x="245" width="80" height="18" fill="red" class="button"/><text y="12" x="251" class="button" fill="white">Update tool</text></g>'
    return o + '</svg>'
예제 #8
0
def main_menu():
	img = libtcod.image_load('menu_background.png')
 
	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, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, libtcod.CENTER,
								 'Steal all that junk!')
		libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Toxy')

		#Show the scoreboard on the left!
		scorewin, scorew, scoreh = ui.show_highscores()
		x = 2
		y = 2
		libtcod.console_blit(scorewin, 0, 0, scorew, scoreh, 0, x, y, 1.0, 0.7)
		#libtcod.console_flush()

		#show options and wait for the player's choice
		choice = ui.menu('', ['Play a new game', 'Continue last saved game', 'Start debug game', 'Save and quit'], 24)
 
		if choice == 0:  #new game
			new_game()
			play_game()
		elif choice == 1:  #load last game
			try:
				load_game()
			except:
				ui.msgbox('\n No saved game to load.\n', 24)
				continue
			play_game()
		elif choice == 2:  #start debug game
			new_debug_game()
			play_game()
		elif choice == 3:  #quit
			break
예제 #9
0
def defile(actor, target, context):
    objects = main.get_objects(target[0],
                               target[1],
                               condition=lambda o: o.is_corpse or o.fighter and
                               o is not actor is not None)
    if len(objects) == 0:
        if actor is player.instance:
            ui.message('There is no body to defile here.', libtcod.gray)
        return 'cancelled'
    elif len(objects) == 1:
        target = objects[0]
    else:
        index = ui.menu('Defile what?', [o.name for o in objects])
        if index is None or index < 0 or index >= len(objects):
            return 'cancelled'
        target = objects[index]

    if target.is_corpse:
        main.raise_dead(actor, target, duration=100)
    elif target.fighter.subtype == 'undead' or target.fighter.subtype == 'fiend':
        target.fighter.heal(int(target.fighter.max_hp / 3))
        ui.message("Dark magic strengthens {}!".format(target.name))
    else:
        combat.attack_magical(actor.fighter, target, 'ability_defile')
예제 #10
0
def main():
    ui.menu()
예제 #11
0
def shatter_item(actor, target, context):
    x, y = 0, 0
    dc = context['save_dc']
    if actor is player.instance:  # player is casting
        ui.message_flush('Left-click a target tile, or right-click to cancel.',
                         libtcod.white)
        (x, y) = ui.target_tile()
        if x is None:
            return 'cancelled'
        choices = main.get_objects(
            x, y, lambda o: o.fighter and o.fighter.inventory and len(
                o.fighter.inventory) > 0)
        if len(choices) == 0:
            choices = main.get_objects(x, y, lambda o: o.item is not None)
        if len(choices) > 1:
            target = choices[ui.menu('Which target?',
                                     [i.name for i in choices], 24)]
        elif len(choices) > 0:
            target = choices[0]
        else:
            ui.message('No valid targets here', libtcod.gray)
            return 'cancelled'
        dc += 4
    else:
        x, y = target.x, target.y

    if target is None:
        return 'cancelled'
    item = None
    inventory = None
    if target.fighter is not None:
        inventory = target.fighter.inventory
        if inventory is None or len(inventory) == 0:
            if actor == player.instance:
                ui.message('Target has no items', libtcod.light_blue)
            return 'cancelled'
        item = inventory[libtcod.random_get_int(0, 0, len(inventory) - 1)]
        dc += 5
    elif target.item is not None:
        item = target

    if main.roll_dice('1d20') + main.roll_dice('1d{}'.format(
            actor.fighter.spell_power())) > dc:
        ui.render_explosion(x, y, 1, libtcod.yellow, libtcod.flame)
        ui.message("The {} shatters into pieces!".format(item.name),
                   libtcod.flame)
        if inventory is not None:
            inventory.remove(item)
        item.destroy()
        damage_factor = 4
        if item.equipment is not None:
            damage_factor = item.equipment.weight
        for obj in main.current_map.fighters:
            if obj.distance(x, y) <= context['burst']:
                combat.attack_magical_ex(
                    actor,
                    obj,
                    base_damage_dice='2d{}'.format(damage_factor),
                    spell_dice_number=context['dice'],
                    spell_elements=context['element'],
                    pierce=context['pierce'],
                    shred=context['shred'],
                    defense_types=context['defense_types'],
                    damage_types=context['damage_types'],
                    blockable=context['blockable'],
                    attack_name=context['name'])
        return 'success'
    else:
        ui.message("Shatter failed to break the {}!".format(item.name),
                   libtcod.yellow)
        return 'success'
예제 #12
0
              "Search by Publishing year", "List all Books", "Go Back")
startMenu = ("Member Login", "Librarian Login", "Quit")
dashboardMenu = ("Issued Books", "Browse/Issue Books", "Log", "My profile",
                 "Logout")
librarianDashboardMenu = ("Log", "Add/Remove Member", "Catalog Operations",
                          "My Profile", "Logout")
failMenu = ("Try Agin", "Go to Home page")
failSearchMenu = ("Try Agin", "Go to Dashboard page")
catalogUpdateMenu = ("Catalog", "Add a Book",
                     "Update a Book's stock/Remove a Book", "Go back")
addRemoveMemberMenu = ("Members", "Add a Member", "Remove a Member", "Go back")
removeUpdateMenu = ("Remove this book", "Update it's stock")

while True:
    ui.clear()
    ui.menu(startMenu)
    startMenuChoice = ui.checkInt(len(startMenu))
    if startMenuChoice == 1:
        memberObj = False
        while True:
            breakFlag = False
            print("++++++ Member Login ++++++")
            username, password = ui.loginMenu()
            memberObj = ui.loginValidation(memberList, username, password)
            if memberObj:
                ui.clear()
                break
            else:
                print(
                    "---------------------------------\nEnter Valid username or password!\n---------------------------------"
                )