def encounter(self, player): #List contents of tile that current player is on options = [obj for obj in self.board.tiles[player.key()].contents if obj is not player] # Break out if current player is only one on the tile # if not options: # return None print("\nHere is your encounter:") print("======================================") print("0. Adventure Card") #List out menu of possible options for i, opt in enumerate(options, start=1): print("%s" % self.generate_encounter_msg(i, opt)) print("======================================") while True: try: choice = int(input(">> ")) if choice == 0: self.draw_adv_card() return None elif choice in range(1, len(options) + 1): break else: print("Invalid choiz") except ValueError: print("Invalid choice") selection = options[choice - 1] #Fight some other player try: if selection.username: try: player.fight([options[choice - 1]]) except AttributeError: #Probably tried to fight something that's not a player pass #Check if enemies defeated me (death=True) if self.check_player_death(player): winner = options[choice - 1] #Winner loots whatever I just dropped self.check_items(winner) else: for opt in options: #Perhaps I defeated enemies if self.check_player_death(opt): # I loot whatever enemy just dropped self.check_items(player) except AttributeError: pass #Pick up item sitting on tile try: if selection.value: player.pickup_items(selection) except AttributeError: pass
def check_items(self, player): # Break out if player is dead if not player.life: return None items = [] for i in self.board.tiles[player.key()].contents: try: if i.value: items.append(i) except AttributeError: pass if items: player.pickup_items(items) for i in items: try: self.board.tiles[player.key()].contents.remove(i) except ValueError: print("ERROR: Item not in tile so I cant remove anything!")