Пример #1
0
    def choice_menu(self, header, err_msg, width, params=[]):
        header += "\n"
        err_msg += "\n"
        ordered_params = []
        if not self.elements:
            options = [err_msg]
        else:
            # correspond the order of params to the order of options
            ordered_elements = [element for element
                                in self.elements.itervalues()]
            options = [element.name for element in ordered_elements]
            for param in params:  # currently supports only one param
                ordered_params = [eval("element."+param) for element
                                  in ordered_elements]
        display.menu(header, options, width, ordered_params)

        key = libtcod.console_wait_for_keypress(True)

        #if key.c == ord('D'):
        #   self.desc_menu(header, err_msg, width)

        #make menu disappear after choice is made
        display.render_all()

        #convert the ASCII code to an index
        index = key.c - ord('a')

        #if something legitimate was chosen, return it
        if index >= 0 and index < len(options):
            if self.elements:
                return self.elements.values()[index]

        return None
Пример #2
0
def inventory_menu():
    while True:
        menu = display.menu(
            "Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow",
            "Back", "Set Consumable", "Set Weapon", "Set Hat", "Set Shirt",
            "Set Pants", "Set Ring")
        while menu.update() is None:
            display.refresh()
        if menu.update() != 0:
            set_active(
                [0, "consumable", "weapon", "hat", "shirt", "pants",
                 "ring"][menu.update()])
        # Redraw equip names.
        display.printc(display.WEAPON_X, display.WEAPON_Y, ' ' * 33)
        display.printc(display.WEAPON_X, display.WEAPON_Y,
                       world.player.attributes["weapon"].name[:33])
        display.printc(display.HAT_X, display.HAT_Y, ' ' * 36)
        display.printc(display.HAT_X, display.HAT_Y,
                       world.player.attributes["hat"].name[:36])
        display.printc(display.SHIRT_X, display.SHIRT_Y, ' ' * 34)
        display.printc(display.SHIRT_X, display.SHIRT_Y,
                       world.player.attributes["shirt"].name[:34])
        display.printc(display.PANTS_X, display.PANTS_Y, ' ' * 34)
        display.printc(display.PANTS_X, display.PANTS_Y,
                       world.player.attributes["pants"].name[:34])
        display.printc(display.RING_X, display.RING_Y, ' ' * 35)
        display.printc(display.RING_X, display.RING_Y,
                       world.player.attributes["ring"].name[:35])
        if menu.update() == 0:
            return
Пример #3
0
 def start_node(this):
     # Create options
     disp_opts = []
     for opt in this.options:
         disp_opts.append(opt[0])
     this.ret_val = None
     display.current_menu = display.menu(this.text, *disp_opts)
Пример #4
0
 def start_node(this, player):
     # Create options
     disp_opts = []
     for opt in this.options:
         disp_opts.append(opt[0])
     this.ret_val = None
     player.attributes["current_menu"] = display.menu(this.text, player, *disp_opts)
Пример #5
0
 def start_node(this):
     # Create options
     disp_opts = []
     for opt in this.options:
         disp_opts.append(opt[0])
     this.ret_val = None
     display.current_menu = display.menu(this.text, *disp_opts)
Пример #6
0
def set_active(type):
    options = []  # All options to go in the menu.
    items = []  # The item corresponding to the option
    for opt in world.player.attributes["items"]:
        if opt.type == type:
            if opt.type == "spell":
                options.append(opt.name + "(" + str(opt.amount) + ")")
            else:
                options.append(opt.name + "(" + str(opt.amount) + ")" +
                               opt.attributes["disp_data"])
            items.append(opt)

    menu = display.menu("Set to what?", "Back", *options)
    while menu.update() is None:
        display.refresh()

    if menu.update() == 0:  # They chose back
        return

    if type != "spell":  # Spells don't have equip and unequip functions.
        world.player.attributes[type].unequip(
            world.player)  # Unequip the old item.
        world.player.attributes[type] = items[menu.update() -
                                              1]  # Find the new item
        world.player.attributes[type].equip(world.player)  # Equip new item
    else:
        world.player.attributes[type] = items[menu.update() - 1]
Пример #7
0
 def start_node(this, player):
     # Create options
     disp_opts = []
     for opt in this.options:
         disp_opts.append(opt[0])
     this.ret_val = None
     player.attributes["current_menu"] = display.menu(
         this.text, player, *disp_opts)
Пример #8
0
def main():
    display.loading()
    display.print_banner()
    print("\n")
    pause = input("Press enter to start..")
    if os.name == "nt":
        windows.process_check()
        windows.hypervisor_check()
        windows.memory_check()
        windows.disk_check()
        windows.rdstc_check()
        windows.registry_check()
        windows.driver_check()
        #windows.guest_additions_check()
    else:
        linux.guest_check()
        linux.memory_check()
        linux.disk_check()
        linux.docker_check()
    display.menu()
Пример #9
0
    def update(this, delta_time):
        plr = this.attributes["player"]
        if plr not in world.players:  # If player leaves, remove this.
            world.to_del.append(this)
            return

        menu = plr.attributes["current_menu"]

        if plr.X == this.X and plr.Y == this.Y:  # Colliding with player.
            # Update menu
            if this.attributes["open"]:
                if menu.update() is not None:  # They chose something
                    if this.attributes["contents"] == []:  # Nothing in chest
                        return
                    #  So add to their stock or create new one.
                    if this.attributes["contents"][
                            menu.update()] in plr.attributes["items"]:
                        # Get their item location
                        plr.attributes["items"][plr.attributes["items"].index(this.attributes["contents"][menu.update()])].amount \
                                 += this.attributes["contents"][menu.update()].amount # And add how many were in the chest.
                    else:  # Give them the item
                        plr.attributes["items"].append(
                            this.attributes["contents"][menu.update(
                            )])  # Giving the player the chest's items.
                    # Remove from chest
                    this.attributes["contents"].remove(
                        this.attributes["contents"][menu.update()])

                    this.attributes["open"] = False  # Close chest
                    plr.attributes["current_menu"] = None
            else:
                if menu is None:  # We can actually make it
                    option_list = []
                    for item in this.attributes["contents"]:
                        option_list.append(item.name + "(" + str(item.amount) +
                                           ")")
                    if option_list != []:
                        plr.attributes["current_menu"] = display.menu(
                            "A Chest!", plr, *option_list)
                        this.attributes["open"] = True

                    else:
                        plr.attributes["sidebar"] += "An empty chest."

        elif this.attributes["open"]:  # Not colliding but opened.
            this.attributes["player"].attributes[
                "current_menu"] = None  # Remove menu
            this.attributes["open"] = False
Пример #10
0
def main():
    display.clear()
    option = display.menu()
    display.clear()
    if option == "0":
        print("Bye :(")
    elif option == "1":
        play()
        main()
    elif option == "2":
        newUser()
        main()
    else:
        input("Not a valid option, press enter to continue...")
        display.clear()
        main()
Пример #11
0
    def update(this, delta_time):
        if world.player.X == this.X and world.player.Y == this.Y:  # Colliding with player.
            # Update menu
            if this.attributes["open"]:
                if display.current_menu.update(
                ) is not None:  # They chose something
                    if this.attributes["contents"] == []:  # Nothing in chest
                        return
                    #  So add to their stock or create new one.
                    if this.attributes["contents"][display.current_menu.update(
                    )] in world.player.attributes["items"]:
                        # Get their item location
                        world.player.attributes["items"][world.player.attributes["items"].index(this.attributes["contents"][display.current_menu.update()])].amount \
                                 += this.attributes["contents"][display.current_menu.update()].amount # And add how many were in the chest.
                    else:  # Give them the item
                        world.player.attributes["items"].append(
                            this.attributes["contents"][
                                display.current_menu.update()]
                        )  # Giving the player the chest's items.
                    # Remove from chest
                    this.attributes["contents"].remove(
                        this.attributes["contents"][
                            display.current_menu.update()])

                    this.attributes["open"] = False  # Close chest
                    display.current_menu = None
            else:
                if display.current_menu is None:  # We can actually make it
                    option_list = []
                    for item in this.attributes["contents"]:
                        option_list.append(item.name)
                    if option_list != []:
                        display.current_menu = display.menu(
                            "A Chest!", *option_list)
                        this.attributes["open"] = True

                    elif display.sidebar_line < 24:
                        display.printc(50, display.sidebar_line,
                                       "An empty chest.")
                        display.sidebar_line += 1

        elif this.attributes["open"]:  # Not colliding but opened.
            display.current_menu.clear()  # Clear right pane
            display.current_menu = None  # Remove menu
            this.attributes["open"] = False
Пример #12
0
def inventory_menu():
    while True:
        menu = display.menu("Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow", "Back", "Set Consumable", "Set Weapon", "Set Hat", "Set Shirt", "Set Pants", "Set Ring")
        while menu.update() is None:
            display.refresh()
        if menu.update() != 0:
            set_active([0, "consumable", "weapon", "hat", "shirt", "pants", "ring"][menu.update()])
        # Redraw equip names.
        display.printc(display.WEAPON_X, display.WEAPON_Y, ' ' * 33)
        display.printc(display.WEAPON_X, display.WEAPON_Y, world.player.attributes["weapon"].name[:33])
        display.printc(display.HAT_X, display.HAT_Y, ' ' * 36)
        display.printc(display.HAT_X, display.HAT_Y, world.player.attributes["hat"].name[:36])
        display.printc(display.SHIRT_X, display.SHIRT_Y, ' ' * 34)
        display.printc(display.SHIRT_X, display.SHIRT_Y, world.player.attributes["shirt"].name[:34]) 
        display.printc(display.PANTS_X, display.PANTS_Y, ' ' * 34)
        display.printc(display.PANTS_X, display.PANTS_Y, world.player.attributes["pants"].name[:34])
        display.printc(display.RING_X, display.RING_Y, ' ' * 35)
        display.printc(display.RING_X, display.RING_Y, world.player.attributes["ring"].name[:35])
        if menu.update() == 0:
            return
Пример #13
0
    def update(this, delta_time):
        plr = this.attributes["player"]
        if plr not in world.players: # If player leaves, remove this.
            world.to_del.append(this)
            return

        menu = plr.attributes["current_menu"]

        if plr.X == this.X and plr.Y == this.Y: # Colliding with player.
            # Update menu
            if this.attributes["open"]:
                if menu.update() is not None: # They chose something
                    if this.attributes["contents"] == []:     # Nothing in chest
                        return
                    #  So add to their stock or create new one.
                    if this.attributes["contents"][menu.update()] in plr.attributes["items"]:
                        # Get their item location
                        plr.attributes["items"][plr.attributes["items"].index(this.attributes["contents"][menu.update()])].amount \
                                 += this.attributes["contents"][menu.update()].amount # And add how many were in the chest.
                    else: # Give them the item
                        plr.attributes["items"].append(this.attributes["contents"][menu.update()]) # Giving the player the chest's items.
                    # Remove from chest
                    this.attributes["contents"].remove(this.attributes["contents"][menu.update()])

                    this.attributes["open"] = False # Close chest
                    plr.attributes["current_menu"] = None
            else:
                if menu is None: # We can actually make it
                    option_list = []
                    for item in this.attributes["contents"]:
                        option_list.append(item.name + "(" + str(item.amount) + ")")
                    if option_list != []:
                        plr.attributes["current_menu"] = display.menu("A Chest!", plr, *option_list)
                        this.attributes["open"] = True

                    else:
                        plr.attributes["sidebar"] += "An empty chest."

        elif this.attributes["open"]:                                           # Not colliding but opened.
            this.attributes["player"].attributes["current_menu"] = None         # Remove menu
            this.attributes["open"] = False
Пример #14
0
def change_settings(custom_scr, grid, level_file):
    item_num = menu(custom_scr, "SETTINGS (q quits)", level_file.setting_names)
    if item_num is None:
        return
    val_for_setting = float(prompt(custom_scr))
    previous_spawn, previous_goal, previous_coin = \
            level_file.spawn_coords, level_file.goal_coords, level_file.coin_coords
    level_file.set_setting(item_num, val_for_setting)
    if item_num in (0, 8):
        grid.set_point(previous_spawn[0], previous_spawn[1],
                       symbols["empty space"])
        grid.set_point(level_file.spawn_coords[0], level_file.spawn_coords[1],
                       symbols["spawn"])
    elif item_num in (3, 9):
        grid.set_point(previous_goal[0], previous_goal[1],
                       symbols["empty space"])
        grid.set_point(level_file.goal_coords[0], level_file.goal_coords[1],
                       symbols["goal"])
    elif item_num in (6, 12):
        grid.set_point(previous_coin[0], previous_coin[1],
                       symbols["empty space"])
        grid.set_point(level_file.coin_coords[0], level_file.coin_coords[1],
                       symbols["coin"])
Пример #15
0
    def update(this, delta_time):
        if world.player.X == this.X and world.player.Y == this.Y: # Colliding with player.
            # Update menu
            if this.attributes["open"]:
                if display.current_menu.update() is not None: # They chose something
                    if this.attributes["contents"] == []:     # Nothing in chest
                        return
                    #  So add to their stock or create new one.
                    if this.attributes["contents"][display.current_menu.update()] in world.player.attributes["items"]:
                        # Get their item location
                        world.player.attributes["items"][world.player.attributes["items"].index(this.attributes["contents"][display.current_menu.update()])].amount \
                                 += this.attributes["contents"][display.current_menu.update()].amount # And add how many were in the chest.
                    else: # Give them the item
                        world.player.attributes["items"].append(this.attributes["contents"][display.current_menu.update()]) # Giving the player the chest's items.
                    # Remove from chest
                    this.attributes["contents"].remove(this.attributes["contents"][display.current_menu.update()])

                    this.attributes["open"] = False # Close chest
                    display.current_menu = None
            else:
                if display.current_menu is None: # We can actually make it
                    option_list = []
                    for item in this.attributes["contents"]:
                        option_list.append(item.name)
                    if option_list != []:
                        display.current_menu = display.menu("A Chest!", *option_list)
                        this.attributes["open"] = True

                    elif display.sidebar_line < 24:
                        display.printc(50, display.sidebar_line, "An empty chest.")
                        display.sidebar_line += 1

        elif this.attributes["open"]:           # Not colliding but opened.
            display.current_menu.clear()        # Clear right pane
            display.current_menu = None         # Remove menu
            this.attributes["open"] = False
Пример #16
0
def set_active(type):
    options = [] # All options to go in the menu.
    items = [] # The item corresponding to the option
    for opt in world.player.attributes["items"]:
        if opt.type == type:
            if opt.type == "spell":
                options.append(opt.name + "(" + str(opt.amount) + ")")
            else:
                options.append(opt.name +"(" + str(opt.amount) + ")" + opt.attributes["disp_data"])
            items.append(opt)

    menu = display.menu("Set to what?", "Back", *options)
    while menu.update() is None:
        display.refresh()

    if menu.update() == 0: # They chose back
        return

    if type != "spell": # Spells don't have equip and unequip functions.
        world.player.attributes[type].unequip(world.player) # Unequip the old item.
        world.player.attributes[type] = items[menu.update() - 1] # Find the new item
        world.player.attributes[type].equip(world.player) # Equip new item
    else:
        world.player.attributes[type] = items[menu.update() - 1]
Пример #17
0
    def update(this, delta_time):
        for plr in world.players:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y -1 <= this.Y:
                if plr.attributes["current_menu"] is None: # Start talking to new players
                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu("Buy or sell?", plr, "Buy", "Sell")

        left_players = []
        for plr in this.attributes["players_start"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y -1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd: # They chose sell
                        can_sell = [] # What items they can sell
                        options  = [] # Text for menu
                        for itm in plr.attributes["items"]:
                            if itm.value > 0:
                                can_sell.append(itm)
                                options.append(itm.name + '(' + str(itm.amount) + ')(\\fy' + str(itm.value) + '\\fw)')
                        plr.attributes["current_menu"] = display.menu("Sell what?", plr, "Nothing", *options)
                        this.attributes["players_selling"][plr] = can_sell
                    else:   # They chose buy
                        can_buy = [] # What items they can buy
                        options = [] # Text for menu
                        for itm in this.attributes["items"]:
                            if itm.value * this.attributes["cost_mult"] * itm.amount <= plr.attributes["money"]: # If they can buy it, add it.
                                can_buy.append(itm)
                                options.append(itm.name + '(' + str(itm.amount) + ')(\\fy' + str(itm.value * this.attributes["cost_mult"] * itm.amount) + '\\fw)')
                        plr.attributes["current_menu"] = display.menu("Buy what?", plr, "Nothing", *options)
                        this.attributes["players_buying"][plr] = can_buy

                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_start"][left]

        left_players.clear()
        for plr in this.attributes["players_buying"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y -1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd != 0:
                        item_bought = this.attributes["players_buying"][plr][upd - 1] # Find chosen item
                        if item_bought.value * this.attributes["cost_mult"] * item_bought.amount <= plr.attributes["money"]: # Give them item if true
                            if item_bought in plr.attributes["items"]:
                                # Get their item location
                                plr.attributes["items"][plr.attributes["items"].index(item_bought)].amount \
                                         += item_bought.amount # And add how many they bought
                            else: # Give them the item
                                plr.attributes["items"].append(copy.deepcopy(item_bought))
                            plr.attributes["money"] -= item_bought.value * this.attributes["cost_mult"] * item_bought.amount

                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu("Buy or sell?", plr, "Buy", "Sell")
                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_buying"][left]

        left_players.clear()
        for plr in this.attributes["players_selling"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y -1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd != 0:
                        item_sold = this.attributes["players_selling"][plr][upd - 1]  # Find chosen item
                        if item_sold in plr.attributes["items"]:  # If they still have it
                            plr.attributes["money"] += item_sold.value # Give gold
                            item_sold.amount -= 1                 # Remove one of it
                            if item_sold.amount <= 0:             # No items left
                                del plr.attributes["items"][plr.attributes["items"].index(item_sold)]  # Remove item from inventory
                                if plr.attributes[item_sold.type] == item_sold: # If equipped
                                    plr.attributes[item_sold.type].unequip(plr)
                                    plr.attributes[item_sold.type] = no_item.make_noitem(item_sold.type)

                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu("Buy or sell?", plr, "Buy", "Sell")
                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_selling"][left]
Пример #18
0
import body as b
import display as d

filename = "students.txt"
data = {}
user = None

try:
    filename = input("Please input the name of the file (with extension): ")
except NameError:
    print(f"{filename} was not found, please make sure the name is correct")

data = b.readFromFile(filename)

user = d.menu()

while user != 6:

    if user == 0:
        d.displayAll(data)
    elif user == 1:
        d.displayGrads(data)
    elif user == 2:
        d.displayGPA(data)
    elif user == 3:
        d.displayDept(data)
    elif user == 4:
        d.sortOnGradDate(data)
    elif user == 5:
        d.sortOnGPA(data)
    else:
Пример #19
0
    def update(this, delta_time):
        this.attributes["sidebar"] = ""
        try:
            if this.attributes["pipe"].poll():
                message = json.loads(this.attributes["pipe"].recv())
                if message["type"] == 'keydown':
                    this.attributes["keys"][message["d"]] = True
                elif message["type"]== 'keyup':
                    this.attributes["keys"][message["d"]] = False
                elif message["type"] == "inv":
                    if message["data"] == "exit":
                        # Just exit inv without doing anything
                        this.attributes["using_inv"] = False
                    else: # Equip the item!
                        to_equip = this.attributes["items"][message["data"]]
                        print(to_equip)
                        this.attributes[to_equip.type].unequip(this)  # Unequip other item
                        this.attributes[to_equip.type] = to_equip     # Put in equipped slot
                        to_equip.equip(this)                          # Equip

                        this.send_inventory()
                this.attributes["timeout"] = 0
            else:
                this.attributes["timeout"] += delta_time
                if this.attributes["timeout"] > 1000 * 10: # No ping in last 10s
                    display.log("Timeout: " + this.attributes["name"])
                    world.to_del_plr.append(this)
                    return
        except Exception as ex:
            world.to_del_plr.append(this)    
            return
        if this.attributes["esc_menu"] is not None:
            opt = this.attributes["esc_menu"].update()

            if opt is not None: # They chose an option
                if this.attributes["esc_menu_type"] == "main":
                    if opt == 0:
                        this.attributes["esc_menu"] = None
                    elif opt == 1:
                        this.attributes["esc_menu"] = None
                        this.attributes["using_inv"] = True
                        this.attributes["keys"] = bytearray(display.NUM_KEYS)
                        this.send_inventory()
                    elif opt == 2:
                        options = [] # All options to go in the menu.
                        spell_list = this.attributes["spells"] # The spell corresponding to the option
                        for spl in spell_list:    # Find all items
                            options.append(spl.name + "(" + str(spl.amount) + ")")
                        this.attributes["esc_menu"] = display.menu("Set to what?", this, "Back", *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "spell"
                    elif opt == 3:
                        options = [] # All options to go in the menu.
                        spell_list = this.attributes["spells"] # The spell corresponding to the option
                        for spl in spell_list:    # Find all items
                            options.append(spl.name + "(" + str(spl.amount) + ")")
                        this.attributes["esc_menu"] = display.menu("Switch what spell?", this, "Back", *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "sorder1"
                    elif opt == 4:
                        this.attributes["esc_menu"] = None
                        world.to_del_plr.append(this)
                        return
                elif this.attributes["esc_menu_type"] == "set": # Let them set an item
                    if opt != 0:
                        itm = this.attributes["set_list"][opt - 1]                  # Find chosen item
                        if itm in this.attributes["items"]:     # If they have the item
                            this.attributes[this.attributes["set_name"]].unequip(this)  # Unequip other item
                            this.attributes[this.attributes["set_name"]] = itm          # Put in equipped slot
                            itm.equip(this)                                             # Equip
                    this.attributes["esc_menu"] = display.menu("Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow\\fw", this, "Back", "Set Consumable", "Set Weapon", "Set Hat", "Set Shirt", "Set Pants", "Set Ring")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "inv"

                elif this.attributes["esc_menu_type"] == "spell": # Let them set a spell
                    if opt != 0:
                        this.attributes["spell"] = opt - 1
                    this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "main"

                elif this.attributes["esc_menu_type"] == "sorder1":
                    if opt != 0:
                        this.attributes["spell_switch"] = opt - 1 # First switch option.
                        options = [] # All options to go in the menu.
                        spell_list = this.attributes["spells"] # The spell corresponding to the option
                        for spl in spell_list:    # Find all items
                            options.append(spl.name + "(" + str(spl.amount) + ")")
                        this.attributes["esc_menu"] = display.menu("Switch with what?", this, *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "sorder2"
                    else:
                        this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server")
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "main"
                elif this.attributes["esc_menu_type"] == "sorder2":
                    # Switch spells
                    this.attributes["spells"][this.attributes["spell_switch"]], this.attributes["spells"][opt] = this.attributes["spells"][opt], this.attributes["spells"][this.attributes["spell_switch"]]
                    this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order", "Exit Server")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "main"
        # Open ESC menu if needed.
        if this.attributes["keys"][display.KEY_ESC] and this.attributes["esc_menu"] is None:
            this.attributes["esc_menu"] = display.menu("Options:", this, "Close Menu", "Inventory", "Spells", "Switch Spell Order","Exit Server")
            this.attributes["esc_menu"].is_esc_menu = True
            this.attributes["esc_menu_type"] = "main"

        # Inventory screen
        if this.attributes["keys"][display.KEY_INVENTORY]:
            this.attributes["using_inv"] = True
            this.attributes["keys"] = bytearray(display.NUM_KEYS)
            this.send_inventory()
        # Check HP diff for flash on hit stuff
        if this.attributes["HP"] < this.attributes["lastHP"]:
            this.attributes["sincehit"] = 0
        else:
            this.attributes["sincehit"] += delta_time

        # Check for movement. TODO: maybe add speed multiplier?
        if this.attributes["keys"][display.KEY_MOV_UP] and (not "del_up" in this.attributes["effects"]):
            if (this.Y > 0) and world.map[this.X][this.Y - 1][3]:
                this.Y -= 1
            this.attributes["effects"]["del_up"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_DOWN] and (not "del_down" in this.attributes["effects"]):
            if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y + 1][3]:
                this.Y += 1
            this.attributes["effects"]["del_down"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_LEFT] and (not "del_left" in this.attributes["effects"]):
            if (this.X > 0) and world.map[this.X - 1][this.Y][3]:
                this.X -= 1
            this.attributes["effects"]["del_left"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_RIGHT] and (not "del_right" in this.attributes["effects"]):
            if (this.X < world.WORLD_X - 1) and world.map[this.X + 1][this.Y][3]:
                this.X += 1
            this.attributes["effects"]["del_right"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["mov_spd"])))

        # Check for spell cast
        if this.attributes["keys"][display.KEY_SPELL] and this.attributes["can_cast"]:
            this.attributes["spells"][this.attributes["spell"]].cast(this)
            this.attributes["can_cast"] = False
        if not this.attributes["keys"][display.KEY_SPELL]:
            this.attributes["can_cast"] = True

        # Check for spell cycle
        if this.attributes["keys"][display.KEY_LASTSPELL] and this.attributes["can_spell_cycle"]:
            if this.attributes["spell"] == 0: # Cycle to end of list if at start
                this.attributes["spell"] = len(this.attributes["spells"])
            this.attributes["spell"] -= 1     # Cycle backwards
            this.attributes["can_spell_cycle"] = False
        if this.attributes["keys"][display.KEY_NEXTSPELL] and this.attributes["can_spell_cycle"]:
            this.attributes["spell"] += 1
            if this.attributes["spell"] >= len(this.attributes["spells"]): # If at end of list, cycle to start
                this.attributes["spell"] = 0
            this.attributes["can_spell_cycle"] = False
        if not (this.attributes["keys"][display.KEY_LASTSPELL] or this.attributes["keys"][display.KEY_NEXTSPELL]):
            this.attributes["can_spell_cycle"] = True

        # Attacks! TODO: maybe add speed multiplier? So you can have really slow weapons.
        if this.attributes["keys"][display.KEY_ATK_UP] and (not "del_atk" in this.attributes["effects"]):
            world.objects.append(attack.attack(this.X, this.Y, 0, -1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_LEFT] and (not "del_atk" in this.attributes["effects"]):
            world.objects.append(attack.attack(this.X, this.Y, -1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_DOWN] and (not "del_atk" in this.attributes["effects"]):
            world.objects.append(attack.attack(this.X, this.Y, 0, 1, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_RIGHT] and (not "del_atk" in this.attributes["effects"]):
            world.objects.append(attack.attack(this.X, this.Y, 1, 0, (this.attributes["strength"] * this.attributes["weapon"].attributes["damage"] // 2), this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(this, 500/(1+2.718**(.01*this.attributes["atk_spd"])))
            # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula.

        # Check for item use
        if this.attributes["keys"][display.KEY_ITEM] and this.attributes["can_item"] and (this.attributes["consumable"].name != "Nothing"):
            this.attributes["consumable"].use(this)
            this.attributes["can_item"] = False
            this.attributes["consumable"].amount -= 1
            if this.attributes["consumable"].amount <= 0:
                del this.attributes["items"][this.attributes["items"].index(this.attributes["consumable"])]
                this.attributes["consumable"] = no_item.no_consumable()
        if not this.attributes["keys"][display.KEY_ITEM]:
            this.attributes["can_item"] = True

        # Update all effects.
        this.attributes["sidebar"] += "Effects:\n"
        sidebar_len = this.attributes["sidebar"].count('\n')

        eff_del_list = []
        for eff_name in this.attributes["effects"]:
            eff = this.attributes["effects"][eff_name]
            eff.tick(delta_time)  # Tick effect
            if eff.time <= 0:           # Remove effect
                eff_del_list.append(eff_name)
        for eff_name in eff_del_list:
            this.attributes["effects"][eff_name].uneffect(this)
            del this.attributes["effects"][eff_name]
        del eff_del_list

        # Reset lastHP, done after effect updating so damaging effects don't force you red.
        this.attributes["lastHP"] = this.attributes["HP"]

        if this.attributes["sidebar"].count('\n') == sidebar_len:
            this.attributes["sidebar"] += " No effects\n"

        if this.attributes["HP"] <= 0: # Dead
            # Remove all effects in case they were on fire for 100hrs or something.
            # Repeatedly dying to that wouldn't be fun.
            # I guess this also adds a slight death penalty if you had a useful effect up.
            for eff_name, eff in this.attributes["effects"].items():
                eff.uneffect(this)
            this.attributes["effects"].clear()

            this.attributes["HP"] = this.attributes["maxHP"]                    # Recover HP, MP
            this.attributes["MP"] = this.attributes["maxMP"]
            this.X = this.attributes["respawnX"]                                # Return to last saved place
            this.Y = this.attributes["respawnY"]
            world.move_requests.append((this.attributes["respawnMap"], this))   # At last saved map...
            world.to_del_plr.append(this)                                       # Exit from this map.
            display.log("Player died" + this.attributes["name"])
Пример #20
0
GPIO.add_event_detect(sw, GPIO.FALLING, callback=sw_callback, bouncetime=300)

try:
    init_return = init()

    if (init_return):
        while True:
            screensaver()
            ret, hashval = finger.search()
            if ret:
                (flag, res) = getAccessByHash(hashval, ip_address, port)
                if (flag):
                    length_menu = len(res["access"])
                    welcome("welcome " + res["username"])

                    menu(0, res["access"])
                    while True:
                        if (clickToggle):
                            clickToggle = False
                            break
                        else:
                            clkState = GPIO.input(clk)
                            dtState = GPIO.input(dt)
                            if clkState != clkLastState:
                                counter += 1
                                menu(counter % (length_menu), res["access"])
                            clkLastState = clkState
                            time.sleep(0.1)
                else:
                    draw_text("Server Error", 0, 0)
                    time.sleep(2)
                verified = True
                break  #we break our loop
            elif user_choice == 2:
                break  #we break our program to change username
            else:
                display.input_warning()

##---------------------------AFTER LOGGED PART-----------------------------##

print("LOGGED AS " + user_name)
user_data = matrix.create("users/" + user_name + ".txt")
#print(user_data)
run = True
while run:  #run program until user wants to quit
    display.heading("menu")
    display.menu()

    #perform action according to user choice
    invalid = True
    while invalid:  #take input until it is valid
        invalid = False
        user_choice = user.choice()

        if user_choice == 1:  #if user select to borrow
            display.heading("which book are you borrowing?")
            display.matrix(book_list)
            user_select = user.choice()
            updated_data = book.borrow_book(user_select, user_data, book_list)
            user_data = updated_data[0]
            book_list = updated_data[1]
            log_msg = updated_data[2]
Пример #22
0
    def update(this, delta_time):
        this.attributes["sidebar"] = ""
        try:
            if this.attributes["pipe"].poll():
                message = json.loads(this.attributes["pipe"].recv())
                if message["type"] == 'keydown':
                    this.attributes["keys"][message["d"]] = True
                elif message["type"] == 'keyup':
                    this.attributes["keys"][message["d"]] = False
                elif message["type"] == "inv":
                    if message["data"] == "exit":
                        # Just exit inv without doing anything
                        this.attributes["using_inv"] = False
                    else:  # Equip the item!
                        to_equip = this.attributes["items"][message["data"]]
                        print(to_equip)
                        this.attributes[to_equip.type].unequip(
                            this)  # Unequip other item
                        this.attributes[
                            to_equip.type] = to_equip  # Put in equipped slot
                        to_equip.equip(this)  # Equip

                        this.send_inventory()
                this.attributes["timeout"] = 0
            else:
                this.attributes["timeout"] += delta_time
                if this.attributes[
                        "timeout"] > 1000 * 10:  # No ping in last 10s
                    display.log("Timeout: " + this.attributes["name"])
                    world.to_del_plr.append(this)
                    return
        except Exception as ex:
            world.to_del_plr.append(this)
            return
        if this.attributes["esc_menu"] is not None:
            opt = this.attributes["esc_menu"].update()

            if opt is not None:  # They chose an option
                if this.attributes["esc_menu_type"] == "main":
                    if opt == 0:
                        this.attributes["esc_menu"] = None
                    elif opt == 1:
                        this.attributes["esc_menu"] = None
                        this.attributes["using_inv"] = True
                        this.attributes["keys"] = bytearray(display.NUM_KEYS)
                        this.send_inventory()
                    elif opt == 2:
                        options = []  # All options to go in the menu.
                        spell_list = this.attributes[
                            "spells"]  # The spell corresponding to the option
                        for spl in spell_list:  # Find all items
                            options.append(spl.name + "(" + str(spl.amount) +
                                           ")")
                        this.attributes["esc_menu"] = display.menu(
                            "Set to what?", this, "Back", *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "spell"
                    elif opt == 3:
                        options = []  # All options to go in the menu.
                        spell_list = this.attributes[
                            "spells"]  # The spell corresponding to the option
                        for spl in spell_list:  # Find all items
                            options.append(spl.name + "(" + str(spl.amount) +
                                           ")")
                        this.attributes["esc_menu"] = display.menu(
                            "Switch what spell?", this, "Back", *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "sorder1"
                    elif opt == 4:
                        this.attributes["esc_menu"] = None
                        world.to_del_plr.append(this)
                        return
                elif this.attributes[
                        "esc_menu_type"] == "set":  # Let them set an item
                    if opt != 0:
                        itm = this.attributes["set_list"][
                            opt - 1]  # Find chosen item
                        if itm in this.attributes[
                                "items"]:  # If they have the item
                            this.attributes[
                                this.attributes["set_name"]].unequip(
                                    this)  # Unequip other item
                            this.attributes[this.attributes[
                                "set_name"]] = itm  # Put in equipped slot
                            itm.equip(this)  # Equip
                    this.attributes["esc_menu"] = display.menu(
                        "Inventory\nMax HP: \\frRed\n\\fwMax MP: \\fbBlue\n\\fwMovement Speed: \\fgGreen\n\\fwAttack Speed: White\nMagic Power: \\fcCyan\n\\fwStrength: \\fmMagenta\n\\fwLuck: \\fyYellow\\fw",
                        this, "Back", "Set Consumable", "Set Weapon",
                        "Set Hat", "Set Shirt", "Set Pants", "Set Ring")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "inv"

                elif this.attributes[
                        "esc_menu_type"] == "spell":  # Let them set a spell
                    if opt != 0:
                        this.attributes["spell"] = opt - 1
                    this.attributes["esc_menu"] = display.menu(
                        "Options:", this, "Close Menu", "Inventory", "Spells",
                        "Switch Spell Order", "Exit Server")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "main"

                elif this.attributes["esc_menu_type"] == "sorder1":
                    if opt != 0:
                        this.attributes[
                            "spell_switch"] = opt - 1  # First switch option.
                        options = []  # All options to go in the menu.
                        spell_list = this.attributes[
                            "spells"]  # The spell corresponding to the option
                        for spl in spell_list:  # Find all items
                            options.append(spl.name + "(" + str(spl.amount) +
                                           ")")
                        this.attributes["esc_menu"] = display.menu(
                            "Switch with what?", this, *options)
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "sorder2"
                    else:
                        this.attributes["esc_menu"] = display.menu(
                            "Options:", this, "Close Menu", "Inventory",
                            "Spells", "Switch Spell Order", "Exit Server")
                        this.attributes["esc_menu"].is_esc_menu = True
                        this.attributes["esc_menu_type"] = "main"
                elif this.attributes["esc_menu_type"] == "sorder2":
                    # Switch spells
                    this.attributes["spells"][
                        this.attributes["spell_switch"]], this.attributes[
                            "spells"][opt] = this.attributes["spells"][
                                opt], this.attributes["spells"][
                                    this.attributes["spell_switch"]]
                    this.attributes["esc_menu"] = display.menu(
                        "Options:", this, "Close Menu", "Inventory", "Spells",
                        "Switch Spell Order", "Exit Server")
                    this.attributes["esc_menu"].is_esc_menu = True
                    this.attributes["esc_menu_type"] = "main"
        # Open ESC menu if needed.
        if this.attributes["keys"][
                display.KEY_ESC] and this.attributes["esc_menu"] is None:
            this.attributes["esc_menu"] = display.menu("Options:", this,
                                                       "Close Menu",
                                                       "Inventory", "Spells",
                                                       "Switch Spell Order",
                                                       "Exit Server")
            this.attributes["esc_menu"].is_esc_menu = True
            this.attributes["esc_menu_type"] = "main"

        # Inventory screen
        if this.attributes["keys"][display.KEY_INVENTORY]:
            this.attributes["using_inv"] = True
            this.attributes["keys"] = bytearray(display.NUM_KEYS)
            this.send_inventory()
        # Check HP diff for flash on hit stuff
        if this.attributes["HP"] < this.attributes["lastHP"]:
            this.attributes["sincehit"] = 0
        else:
            this.attributes["sincehit"] += delta_time

        # Check for movement. TODO: maybe add speed multiplier?
        if this.attributes["keys"][display.KEY_MOV_UP] and (
                not "del_up" in this.attributes["effects"]):
            if (this.Y > 0) and world.map[this.X][this.Y - 1][3]:
                this.Y -= 1
            this.attributes["effects"]["del_up"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_DOWN] and (
                not "del_down" in this.attributes["effects"]):
            if (this.Y < world.WORLD_Y - 1) and world.map[this.X][this.Y +
                                                                  1][3]:
                this.Y += 1
            this.attributes["effects"]["del_down"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_LEFT] and (
                not "del_left" in this.attributes["effects"]):
            if (this.X > 0) and world.map[this.X - 1][this.Y][3]:
                this.X -= 1
            this.attributes["effects"]["del_left"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"])))
        if this.attributes["keys"][display.KEY_MOV_RIGHT] and (
                not "del_right" in this.attributes["effects"]):
            if (this.X < world.WORLD_X - 1) and world.map[this.X +
                                                          1][this.Y][3]:
                this.X += 1
            this.attributes["effects"]["del_right"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["mov_spd"])))

        # Check for spell cast
        if this.attributes["keys"][
                display.KEY_SPELL] and this.attributes["can_cast"]:
            this.attributes["spells"][this.attributes["spell"]].cast(this)
            this.attributes["can_cast"] = False
        if not this.attributes["keys"][display.KEY_SPELL]:
            this.attributes["can_cast"] = True

        # Check for spell cycle
        if this.attributes["keys"][
                display.KEY_LASTSPELL] and this.attributes["can_spell_cycle"]:
            if this.attributes[
                    "spell"] == 0:  # Cycle to end of list if at start
                this.attributes["spell"] = len(this.attributes["spells"])
            this.attributes["spell"] -= 1  # Cycle backwards
            this.attributes["can_spell_cycle"] = False
        if this.attributes["keys"][
                display.KEY_NEXTSPELL] and this.attributes["can_spell_cycle"]:
            this.attributes["spell"] += 1
            if this.attributes["spell"] >= len(
                    this.attributes["spells"]
            ):  # If at end of list, cycle to start
                this.attributes["spell"] = 0
            this.attributes["can_spell_cycle"] = False
        if not (this.attributes["keys"][display.KEY_LASTSPELL]
                or this.attributes["keys"][display.KEY_NEXTSPELL]):
            this.attributes["can_spell_cycle"] = True

        # Attacks! TODO: maybe add speed multiplier? So you can have really slow weapons.
        if this.attributes["keys"][display.KEY_ATK_UP] and (
                not "del_atk" in this.attributes["effects"]):
            world.objects.append(
                attack.attack(
                    this.X, this.Y, 0, -1,
                    (this.attributes["strength"] *
                     this.attributes["weapon"].attributes["damage"] // 2),
                    this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_LEFT] and (
                not "del_atk" in this.attributes["effects"]):
            world.objects.append(
                attack.attack(
                    this.X, this.Y, -1, 0,
                    (this.attributes["strength"] *
                     this.attributes["weapon"].attributes["damage"] // 2),
                    this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_DOWN] and (
                not "del_atk" in this.attributes["effects"]):
            world.objects.append(
                attack.attack(
                    this.X, this.Y, 0, 1,
                    (this.attributes["strength"] *
                     this.attributes["weapon"].attributes["damage"] // 2),
                    this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"])))

        if this.attributes["keys"][display.KEY_ATK_RIGHT] and (
                not "del_atk" in this.attributes["effects"]):
            world.objects.append(
                attack.attack(
                    this.X, this.Y, 1, 0,
                    (this.attributes["strength"] *
                     this.attributes["weapon"].attributes["damage"] // 2),
                    this.attributes["weapon"].attributes["range"], 100, this))
            this.attributes["effects"]["del_atk"] = effect.effect(
                this, 500 / (1 + 2.718**(.01 * this.attributes["atk_spd"])))
            # Or with our constants in python, time = 500/(1+2.718^(.01x)), which is a nice logistic formula.

        # Check for item use
        if this.attributes["keys"][
                display.KEY_ITEM] and this.attributes["can_item"] and (
                    this.attributes["consumable"].name != "Nothing"):
            this.attributes["consumable"].use(this)
            this.attributes["can_item"] = False
            this.attributes["consumable"].amount -= 1
            if this.attributes["consumable"].amount <= 0:
                del this.attributes["items"][this.attributes["items"].index(
                    this.attributes["consumable"])]
                this.attributes["consumable"] = no_item.no_consumable()
        if not this.attributes["keys"][display.KEY_ITEM]:
            this.attributes["can_item"] = True

        # Update all effects.
        this.attributes["sidebar"] += "Effects:\n"
        sidebar_len = this.attributes["sidebar"].count('\n')

        eff_del_list = []
        for eff_name in this.attributes["effects"]:
            eff = this.attributes["effects"][eff_name]
            eff.tick(delta_time)  # Tick effect
            if eff.time <= 0:  # Remove effect
                eff_del_list.append(eff_name)
        for eff_name in eff_del_list:
            this.attributes["effects"][eff_name].uneffect(this)
            del this.attributes["effects"][eff_name]
        del eff_del_list

        # Reset lastHP, done after effect updating so damaging effects don't force you red.
        this.attributes["lastHP"] = this.attributes["HP"]

        if this.attributes["sidebar"].count('\n') == sidebar_len:
            this.attributes["sidebar"] += " No effects\n"

        if this.attributes["HP"] <= 0:  # Dead
            # Remove all effects in case they were on fire for 100hrs or something.
            # Repeatedly dying to that wouldn't be fun.
            # I guess this also adds a slight death penalty if you had a useful effect up.
            for eff_name, eff in this.attributes["effects"].items():
                eff.uneffect(this)
            this.attributes["effects"].clear()

            this.attributes["HP"] = this.attributes["maxHP"]  # Recover HP, MP
            this.attributes["MP"] = this.attributes["maxMP"]
            this.X = this.attributes["respawnX"]  # Return to last saved place
            this.Y = this.attributes["respawnY"]
            world.move_requests.append(
                (this.attributes["respawnMap"], this))  # At last saved map...
            world.to_del_plr.append(this)  # Exit from this map.
            display.log("Player died" + this.attributes["name"])
Пример #23
0
     else:
         # And now redraw it
         display.printc(obj.X, obj.Y + 5, obj.char(), obj.color(), world.map[obj.X][obj.Y][1])
 if new_map_loaded:
     if display.current_menu is not None:    # End menu on new map load, don't want extra stuff left over.
         display.current_menu.clear()
         display.current_menu = None
     continue
 # Delete objects that need to be deleted.
 for obj in set(world.to_del): # Set to remove duplicates
     # Only print if in bounds
     if not world.out_of_bounds(obj.X, obj.Y):
         display.printc(obj.X, obj.Y + 5, world.map[obj.X][obj.Y][2], world.map[obj.X][obj.Y][0])
     world.objects.remove(obj)
 if display.keyDown(display.CONST.VK_ESCAPE):
     menu = display.menu("Options:", "Resume", "Inventory", "Spells", "Save", "Exit")
     while menu.update() is None: # Blocking operation for main menu
         display.refresh()
     if menu.update() == 1: # Inventory
         Player.player.inventory_menu()
     elif menu.update() == 2: # Spells
         Player.player.set_active("spell")
     elif menu.update() == 3: # Save
         world.save_player()
     elif menu.update() == 4:
         exit(0)
     
     world.player.attributes["spell"].draw()
     world.player.attributes["consumable"].draw()
     if display.current_menu is not None: # Redraw old menu.
         display.current_menu.redraw()
Пример #24
0
    def update(this, delta_time):
        for plr in world.players:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y - 1 <= this.Y:
                if plr.attributes[
                        "current_menu"] is None:  # Start talking to new players
                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu(
                        "Buy or sell?", plr, "Buy", "Sell")

        left_players = []
        for plr in this.attributes["players_start"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y - 1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd:  # They chose sell
                        can_sell = []  # What items they can sell
                        options = []  # Text for menu
                        for itm in plr.attributes["items"]:
                            if itm.value > 0:
                                can_sell.append(itm)
                                options.append(itm.name + '(' +
                                               str(itm.amount) + ')(\\fy' +
                                               str(itm.value) + '\\fw)')
                        plr.attributes["current_menu"] = display.menu(
                            "Sell what?", plr, "Nothing", *options)
                        this.attributes["players_selling"][plr] = can_sell
                    else:  # They chose buy
                        can_buy = []  # What items they can buy
                        options = []  # Text for menu
                        for itm in this.attributes["items"]:
                            if itm.value * this.attributes[
                                    "cost_mult"] * itm.amount <= plr.attributes[
                                        "money"]:  # If they can buy it, add it.
                                can_buy.append(itm)
                                options.append(
                                    itm.name + '(' + str(itm.amount) +
                                    ')(\\fy' +
                                    str(itm.value *
                                        this.attributes["cost_mult"] *
                                        itm.amount) + '\\fw)')
                        plr.attributes["current_menu"] = display.menu(
                            "Buy what?", plr, "Nothing", *options)
                        this.attributes["players_buying"][plr] = can_buy

                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_start"][left]

        left_players.clear()
        for plr in this.attributes["players_buying"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y - 1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd != 0:
                        item_bought = this.attributes["players_buying"][plr][
                            upd - 1]  # Find chosen item
                        if item_bought.value * this.attributes[
                                "cost_mult"] * item_bought.amount <= plr.attributes[
                                    "money"]:  # Give them item if true
                            if item_bought in plr.attributes["items"]:
                                # Get their item location
                                plr.attributes["items"][plr.attributes["items"].index(item_bought)].amount \
                                         += item_bought.amount # And add how many they bought
                            else:  # Give them the item
                                plr.attributes["items"].append(
                                    copy.deepcopy(item_bought))
                            plr.attributes[
                                "money"] -= item_bought.value * this.attributes[
                                    "cost_mult"] * item_bought.amount

                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu(
                        "Buy or sell?", plr, "Buy", "Sell")
                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_buying"][left]

        left_players.clear()
        for plr in this.attributes["players_selling"]:
            if plr.X + 1 >= this.X and plr.X - 1 <= this.X and plr.Y + 1 >= this.Y and plr.Y - 1 <= this.Y:
                upd = plr.attributes["current_menu"].update()
                if upd is not None:
                    if upd != 0:
                        item_sold = this.attributes["players_selling"][plr][
                            upd - 1]  # Find chosen item
                        if item_sold in plr.attributes[
                                "items"]:  # If they still have it
                            plr.attributes[
                                "money"] += item_sold.value  # Give gold
                            item_sold.amount -= 1  # Remove one of it
                            if item_sold.amount <= 0:  # No items left
                                del plr.attributes["items"][
                                    plr.attributes["items"].index(
                                        item_sold
                                    )]  # Remove item from inventory
                                if plr.attributes[
                                        item_sold.
                                        type] == item_sold:  # If equipped
                                    plr.attributes[item_sold.type].unequip(plr)
                                    plr.attributes[
                                        item_sold.type] = no_item.make_noitem(
                                            item_sold.type)

                    this.attributes["players_start"][plr] = 0
                    plr.attributes["current_menu"] = display.menu(
                        "Buy or sell?", plr, "Buy", "Sell")
                    left_players.append(plr)
            else:
                plr.attributes["current_menu"] = None
                left_players.append(plr)
            if plr not in world.players:
                left_players.append(plr)

        for left in left_players:
            del this.attributes["players_selling"][left]