예제 #1
0
    def run(self, gamedata, *args):
        if len(gamedata.player.inventory) == 0:
            print("Your inventory is empty.")
            return QUIT, gamedata
        util.print_inventory_contents(gamedata.player)
        i = input(
            "Type 'quit' or the name of the item you want to use/drop:\n> ")
        allowed_inputs = []
        for item in gamedata.player.inventory:
            allowed_inputs.append(item.name)
        allowed_inputs.append("quit")
        if util.check_input(i, *allowed_inputs):
            if i == "quit":
                return QUIT, gamedata
            inventory_names = util.get_inventory_names(
                gamedata.player.inventory)
            if i in inventory_names:
                chosen_item = next(
                    (x for x in gamedata.player.inventory if x.name == i),
                    None)
                i2 = input(
                    "Do you want to 'use' or 'drop' {0}? Else 'quit'.\n> ".
                    format(chosen_item.name))  # print name of item
                if util.check_input(i2, "use", "drop",
                                    "quit"):  # check if input2 is legal
                    if i2 == "drop":
                        print("Droppend {0}".format(chosen_item.name))
                        gamedata.player.inventory.remove(chosen_item)
                        return LIST, gamedata
                    if i2 == "quit":
                        return LIST, gamedata
                    if i2 == "use":  # TODO implement use of potions
                        if chosen_item.type == "consumable":
                            util.update_player_stats(gamedata.player,
                                                     chosen_item)
                            gamedata.player.inventory.remove(chosen_item)
                            print("Increased your {0} by {1}".format(
                                chosen_item.influenced_attribute,
                                chosen_item.value))
                            return LIST, gamedata
                        else:
                            print(
                                "{0} is not consumable. Please choose another item"
                                .format(chosen_item.name))
                            return LIST, gamedata

                else:
                    return LIST, gamedata

        else:
            return LIST, gamedata
예제 #2
0
파일: dungeon.py 프로젝트: DevFabrx/Dungeon
 def run(self, gamedata, *args):
     print("0. \t look around")
     print("1. \t move")
     print("2. \t open")
     print("3. \t attack")
     print("4. \t open inventory")
     print("5. \t run away (leave dungeon)")
     i = input("> ")
     if util.check_input(i, "0", "1", "2", "3", "4", "5"):
         if i == str(0):
             return LOOK, gamedata
         elif i == str(1):
             return MOVE, gamedata
         elif i == str(2):
             if gamedata.rooms[gamedata.room_index].treasure is not None:
                 return OPEN, gamedata
             else:
                 print("There is no treasure found in this room.")
                 return MENU, gamedata
         elif i == str(3):
             if len(gamedata.rooms[gamedata.room_index].enemies) != 0:
                 return ATTACK, gamedata
             else:
                 print("There are no enemies in this room.")
                 return MENU, gamedata
         elif i == str(4):
             return INVENTORY, gamedata
         elif i == str(5):
             return EXIT, gamedata
     else:
         print("Please enter a number from 0-5")
         return MENU, gamedata
예제 #3
0
파일: dungeon.py 프로젝트: DevFabrx/Dungeon
 def run(self, gamedata, *args):
     if len(gamedata.rooms[gamedata.room_index].treasure) == 0:
         print("Treasure is empty.")
         return MENU, gamedata
     util.print_treasure(gamedata.rooms[gamedata.room_index].treasure)
     i = input(
         "Insert 'quit' or the name of the item you want to pick up?\n> ")
     allowed_inputs = util.get_treasure_contents(
         gamedata.rooms[gamedata.room_index].treasure)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return MENU, gamedata
         chosen_item = next(
             (x for x in gamedata.rooms[gamedata.room_index].treasure
              if x.name == i), None)
         gamedata.player.inventory.append(chosen_item)
         if chosen_item.type != "consumable":
             util.update_player_stats(gamedata.player, chosen_item)
         gamedata.rooms[gamedata.room_index].treasure.remove(chosen_item)
         print("You picked up {0}".format(chosen_item.name))
         return OPEN, gamedata
     else:
         print("Please input Y/N")
         return OPEN, gamedata
예제 #4
0
파일: village.py 프로젝트: DevFabrx/Dungeon
 def run(self, gamedata, *args):
     i = input("Please choose your destination [0-8]:\n> ")
     print("")
     if util.check_input(i, "0", "1", "2", "3", "4", "5", "6", "7", "8"):
         if i == "0":
             return DUNGEON, gamedata
         elif i == "1":
             return INVENTORY, gamedata
         elif i == "2":
             return RETAILER, gamedata
         elif i == "3":
             return SMITH, gamedata
         elif i == "4":
             return DRUID, gamedata
         elif i == "5":
             return CHEST, gamedata
         elif i == "6":
             return GRAVEDIGGER, gamedata
         elif i == "7":
             return SAVE, gamedata
         elif i == "8":
             return QUIT, gamedata
     else:
         print("Please enter a number from 0-8")
         return CHOOSE, gamedata
예제 #5
0
 def run(self, gamedata, *args):
     if len(gamedata.gravedigger_offerings) == 0:
         print("No items left.")
         return QUIT, gamedata
     i = input("Type 'quit' or the name of the item you want to buy:\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.gravedigger_offerings)
     allowed_inputs.append("quit")
     print(allowed_inputs)
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next((x for x in gamedata.gravedigger_offerings if x.name == i), None)
         if gamedata.player.gold < chosen_item.price:
             print("You do not have enough money to buy this item")
             return CHOOSE, gamedata
         gamedata.player.gold -= math.floor(chosen_item.price)
         print("You have chosen {0}.\nYou now have {1} gold.\nAdded item to your inventory.\n"
               .format(chosen_item.name, gamedata.player.gold))
         gamedata.player.inventory.append(chosen_item)
         if chosen_item.type != "consumable":
             util.update_player_stats(gamedata.player, chosen_item)
         gamedata.gravedigger_offerings.remove(chosen_item)
         return LIST, gamedata
     else:
         print("Please insert the name of the item you want to buy or 'quit'")
         util.print_gravedigger_offering(gamedata)
         return CHOOSE, gamedata
예제 #6
0
 def run(self, gamedata, *args):
     if len(gamedata.player.inventory) == 0:
         print("You do not have anything to store.")
         return QUIT, gamedata
     print("This are your items in your inventory:")
     util.print_inventory_contents(gamedata.player)
     i = input(
         "What item do you want to store in your chest? Else 'quit'\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.player.inventory)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.player.inventory if x.name == i), None)
         gamedata.player.chest = []
         gamedata.player.chest.append(chosen_item)
         print(
             "You have choosen {0} to add to your chest.\nRemoved item from inventory.\n"
             .format(chosen_item.name))
         gamedata.player.inventory.remove(chosen_item)
         return DECIDE, gamedata
     else:
         print(
             "Please insert the name of the item you want to store or 'quit'."
         )
         return STORE, gamedata
예제 #7
0
    def getOptions(self):
        '''
		Construye el objeto de opciones, analizando tanto el fichero de configuración como los parámetros.
		'''
        #
        # Leemos primero los parámetros para poder contemplar el especificar un fichero de configuración diferente.
        #
        global VERBOSITY_LEVEL

        (paramOptions, paramArgs) = self.parseArgs()
        if paramOptions.config != None:
            self.iniParser.ini_path = paramOptions.config

        self.iniParser.parseIni()
        self.options = self.iniParser.options
        VERBOSITY_LEVEL = log.ERROR - 10 * paramOptions.verbosity

        if paramOptions.brewerid is not None:
            self.options.brewerid = paramOptions.brewerid
        if paramOptions.servers is not None:
            self.options.servers = paramOptions.servers
        if paramOptions.input is not None:
            self.options.input = paramOptions.input

        #
        # Comprobamos las opciones mínimas.
        #
        if self.options.servers is None:
            raise ParamException("-s must be specified")
        if self.options.brewerid is None:
            raise ParamException("-b must be specified")
        if self.options.input is None:
            raise ParamException("-i must be specified")
        if self.options.rundir is None:
            raise IniException(
                "'working_dir' option must be specified in .ini file")

        util.check_input(self.options.input)
        self.options.brewerid = util.check_brewerid(self.options.brewerid)
예제 #8
0
 def run(self, gamedata, *args):
     i = input(
         "Do you want to 'store' or 'take' an item with you? Else 'quit'.\n> "
     )
     if util.check_input(i, "store", "take", "quit"):
         if i == "store":
             return STORE, gamedata
         if i == "take":
             return TAKE, gamedata
         if i == "quit":
             return QUIT, gamedata
     else:
         print("Please input 'store', 'take' or 'quit'")
         return DECIDE, gamedata
예제 #9
0
    def run(self, gamedata, *args):
        i = input("Type 'quit' or the name of the item you want to sell:\n> ")
        allowed_inputs = util.get_inventory_names(gamedata.player.inventory)
        allowed_inputs.append("quit")
        if util.check_input(i, *allowed_inputs):
            if i == "quit":
                return QUIT, gamedata
            chosen_item = next((x for x in gamedata.player.inventory if x.name == i), None)
            gamedata.player.gold += math.floor(chosen_item.price * 0.5)
            print("You have choosen {0}.\nYou now have {1} gold.\nRemoved item from inventory.\n"
                  .format(chosen_item.name, gamedata.player.gold))

            gamedata.player.inventory.remove(chosen_item)
            return LIST, gamedata
        else:
            return CHOOSE, gamedata
예제 #10
0
파일: dungeon.py 프로젝트: DevFabrx/Dungeon
 def run(self, gamedata, *args):
     if len(gamedata.rooms[gamedata.room_index].enemies) == 0:
         print("No enemies left to attack!")
         return MENU, gamedata
     if len(gamedata.rooms[gamedata.room_index].enemies) != 0:
         gamedata.rooms[gamedata.room_index].print_enemy_stats()
         util.print_player_health(gamedata.player)
         i = input("Which enemy do you want to attack?\n > ")
         # check for the allowed inputs
         allowed_inputs = []
         iterator = 0
         for enemy in gamedata.rooms[gamedata.room_index].enemies:
             allowed_inputs.append(str(iterator))
             iterator += 1
     if util.check_input(i, *allowed_inputs):
         gamedata.target_enemy = int(i)
         return FIGHT, gamedata
     else:
         print("Please choose an enemy to attack.")
         # gamedata.rooms[gamedata.room_index].print_enemy_stats()
         return ATTACK, gamedata
예제 #11
0
 def run(self, gamedata, *args):
     i = input("Type 'quit' or the name of the item you want to buy:\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.druid_offerings)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.druid_offerings if x.name == i), None)
         if gamedata.player.gold < chosen_item.price:
             print("You do not have enough money to buy this item")
             return CHOOSE, gamedata
         gamedata.player.gold -= math.floor(chosen_item.price)
         print(
             "You have choosen {0}.\nYou now have {1} gold.\nAdded item to your inventory.\n"
             .format(chosen_item.name, gamedata.player.gold))
         gamedata.player.inventory.append(chosen_item)
         return LIST, gamedata
     else:
         print(
             "Please insert the name of the item you want to buy or 'quit'")
         return CHOOSE, gamedata
예제 #12
0
 def run(self, gamedata, *args):
     if len(gamedata.player.chest) == 0:
         print("Your chest is empty.")
         return START, gamedata
     util.print_chest_items(gamedata.player.chest)
     i = input("What item do you want to take from the chest?\n> ")
     allowed_inputs = util.get_inventory_names(gamedata.player.chest)
     allowed_inputs.append("quit")
     if util.check_input(i, *allowed_inputs):
         if i == "quit":
             return QUIT, gamedata
         chosen_item = next(
             (x for x in gamedata.player.chest if x.name == i), None)
         gamedata.player.inventory.append(chosen_item)
         print(
             "You have choosen {0} to add to your inventory.\nRemoved item from chest.\n"
             .format(chosen_item.name))
         gamedata.player.chest.remove(chosen_item)
         return START, gamedata
     else:
         print(
             "Please insert the name of the item you want to take or 'quit'."
         )
         return TAKE, gamedata
예제 #13
0
파일: desktop.py 프로젝트: 371114769/Python
 def __init__(self, season: str):
     self.contents = []
     season = check_input(season)
     self.get_season_content(season)