def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") if player.inventory: # same as: "if player.inventory != []" (is not empty) action_adder(actions, 'i', player.print_inventory, "Print inventory") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, (world.EnemyTile, world.BossTile)) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") # if isinstance(room, (world.InstantDeathTile, world.BossTile)): # action_adder(actions, 'u', player.use_item, "Use item") else: if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go west") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") return actions
def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") action_adder(actions, '?', player.status, "Player Status") enemy_alive = any(bad_guy.is_alive() for bad_guy in room.enemy_que) if not room.enemy_que == [] and enemy_alive: action_adder(actions, 'a', player.attack, "Attack") action_adder(actions, 'f', player.flee, "Flee (run-away!)") else: if not room.enemy_que == [] and not enemy_alive: action_adder(actions, 'l', player.loot_corpse, "Loot corpse") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print Inventory") action_adder(actions, 'd', player.drop_item, "Drop item from Inventory") if room_items_takeable(room): action_adder(actions, 'g', player.get_item, "Get item(s) in room") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go North") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go South") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go East") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go West") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") return actions
def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") action_adder(actions, 'p', player.print_map, 'Print map') if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print inventory") if player.equip: action_adder(actions, 'x', player.equip, "Equip") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if (isinstance(room, world.EnemyTile) or isinstance(room, world.BlackKnightTile) or isinstance(room, world.BossTile)) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") action_adder(actions, 'm', player.magic_attack, "Magic attack") else: if world.tile_at(room.x + 1, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x + 1, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go west") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") if player.mana < 100: action_adder(actions, 'k', player.regen_mana, 'Mana') return actions
def get_available_actions(room,player): actions = OrderedDict() print("Choose an action:") if player.inventory: action_adder(actions,'i', player.print_inventory, "Print inventory") if isinstance(room, world.TraderTile): action_adder(actions,'t',player.trade,"Trade") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions,'a',player.attack,"Attack") else: if world.tile_at(room.x, room.y - 1): # map tile (x/y co ordinates) linked to directional navigation action_adder(actions,'n', player.move_north,"Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions,'s', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions,'e', player.move_east,"Go east") if world.tile_at(room.x -1, room.y): action_adder(actions,'w', player.move_west,"Go west") if player.hp < 100: action_adder(actions,'h', player.heal,"Heal") return actions def action_adder(action_dict, hotkey, action, name): action_dict[hotkey.lower()] = action action_dict[hotkey.upper()] = action print("{}: {}".format(hotkey,name)) play()
def get_available_actions(room, player): actions = OrderedDict() print("What are your orders Herr Kaleun? Available orders are:") if player: action_adder(actions, 'q', player.exit, "Quit the game") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print Inventory") if isinstance(room, world.GenericMerchantTile) and room.enemy.is_alive(): action_adder(actions, 't', player.attack1, "Attack with a torpedo") if isinstance(room, world.GenericMerchantTile) and room.enemy.is_alive(): action_adder(actions, 'd', player.attack2, "Attack with the deck gun") if isinstance(room, world.GenericWarshipTile) and room.enemy.is_alive(): action_adder(actions, 't', player.attack1, "Attack with a torpedo") if isinstance(room, world.GenericWarshipTile) and room.enemy.is_alive(): action_adder(actions, 'd', player.attack2, "Attack with the deck gun") else: if world.tile_at(room.x - 1, room.y): action_adder(actions, 'n', player.move_North, "Go North") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_South, "Go South") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_East, "Go East") if world.tile_at(room.x, room.y - 1): action_adder(actions, 'w', player.move_West, "Go West") return actions
def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print inventory") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") else: if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go North") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go East") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_north, "Go West") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_north, "Go South") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") return actions
def get_available_actions(room, player): actions = OrderedDict() print("[Choose an action: ]") # Action based options if player.inventory: action_adder(actions, "i", player.print_inventory, "Look at your inventory") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, "a", player.attack, "Attack") if isinstance(room, world.OutsideTile) and player.drone == 1: action_adder(actions, "L", player.launch, "LAUNCH DRONE") if isinstance(room, world.TraderTile) or isinstance(room, world.PedasTile): action_adder(actions, "T", player.trade, "TRADE") if player.check_beer(): action_adder(actions, "d", player.drink, "Drink beer") if player.check_mee(): action_adder(actions, "m", player.eat, "Eat mee goreng spicy") # Movement based options if world.tile_at(room.x, room.y - 1): action_adder(actions, "n", player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, "s", player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, "e", player.move_east, "Go east") if world.tile_at(room.x - 1, room.y): action_adder(actions, "w", player.move_west, "Go west") if player.hp <= 0: print("Your journey has come to an end!") end() return actions
def play(): world.parse_world_dsl() # load tiles player = Player(world.starting_position) #These lines load the starting room and display the text room = world.tile_at(player.location_x, player.location_y) print(intro_text) while player.is_alive() and not player.victory: #Loop begins here room = world.tile_at(player.location_x, player.location_y) # import ipdb; ipdb.set_trace() room.modify_player(player) # Check again since the room could have changed the player's state if player.is_alive() and not player.victory: print(room.intro_text(player)) print("Choose an action:\n") available_actions = room.available_actions() for action in available_actions: print(action) action_input = input('Action: ') for action in available_actions: if action_input == action.hotkey: player.do_action(action, **action.kwargs) break
def get_available_actions(room, player): actions = OrderedDict() print("") print("Choose an action: ") action_adder(actions, 'c', player.coords, "View coordinates") action_adder(actions, 'm', player.menu, "Open Menu") action_adder(actions, 'l33thax0r', player.hax, "HAX") action_adder(actions, 'a11th3st0ps', player.all, "HAX") if player.inventory: action_adder(actions, 'i', player.print_inventory, "View inventory") if isinstance(room, world.TradingNPCs): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, world.ChooseMap): action_adder(actions, 't', player.travel, "Travel") if isinstance(room, world.Chest) and room.loot_claimed == False: action_adder(actions, 'o', player.openChest, "Open Chest") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") else: if isinstance(room, world.TrainingDummy) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack Dummy") if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go west") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") return actions
def get_available_actions(room, player): actions = collections.OrderedDict() print("Choose an Action: ") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print inventory") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") else: if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world.tile_at(room.x - 1, room.y - 1): action_adder(actions, 'w', player.move_west, "Go west") if player.hp < player.MAX_HITPOINTS: action_adder(actions, 'h', player.heal, "Heal") action_adder(actions, 'q', player.quit, "Quit") return actions
def get_available_action(room, player): actions = OrderedDict() print("Choose an action: ") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print Inventory") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, world.EnemyTile) and not room.enemy.is_alive(): action_adder(actions, 'inv', player.investigate, "Investigate Corpse") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") action_adder(actions, 'sp', player.spell_attack, "Spell Attack") else: if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world. tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go west") if player.currentHP < 100: action_adder(actions, 'h', player.heal, "Heal") action_adder(actions, 'st', player.status, "Stats") return actions
def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") print("Hotkey and typing the word both work.") if isinstance(room, world.TraderTile): action_adder(actions, 't', "TRADE", player.trade, "Trade") if isinstance(room, world.StartTile): action_adder(actions, 'd', "DROP", player.drop_item, "Drop in Room") if isinstance(room, world.StartTile): action_adder(actions, 'p', "PICK", player.pick_up_item, "Pick out of Room") if player.inventory: action_adder(actions, "i", "INVENTORY", player.print_inventory, "View Inventory") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', "ATTACK", player.attack, "Attack") if isinstance(room, world.BossTile) and room.enemy.is_alive(): action_adder(actions, 'a', "ATTACK", player.attack, "Attack") if isinstance(room, world.VictoryTile) and room.enemy.is_alive(): action_adder(actions, 'a', "ATTACK", player.attack, "Attack") else: if not world.ThreeTile or world.TwoTile or world.FourTile or world.EightTile or world.NineTile: if world.tile_at(room.x, room.y -1): action_adder(actions, 'n', "GO NORTH", player.move_north, "Go North") if world.tile_at(room.x, room.y + 1): action_adder(actions, "s", "GO SOUTH", player.move_south, "Go South") if world.tile_at(room.x + 1, room.y): action_adder(actions, "e", "GO EAST", player.move_east, "Go East") if world.tile_at(room.x - 1, room.y): action_adder(actions, "w", "GO WEST", player.move_west, "Go West") if player.look_around: action_adder(actions, "l", "LOOK", player.look_around, "Look Around") if player.hp < 100: action_adder(actions, "h", "HEAL", player.heal, "Heal") if isinstance(room, world.StartTile): action_adder(actions, "v", "SPEAK", player.speak, "Speak to the Witch") if isinstance(room, world.TenTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to Quest Giver") if isinstance(room, world.TwoTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to Quest Giver") if isinstance(room, world.ThreeTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to Quest Giver") if isinstance(room, world.FourTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to Quest Giver") if isinstance(room, world.EightTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to Quest Giver") if isinstance(room, world.SevenTile): action_adder(actions, "g", "GIVER", player.getquest, "Talk to the Quest Giver") action_adder(actions, "q", "QUIT", player.quit, "Quit") action_adder(actions, "h", "HELP", player.help, "Help") if isinstance(room, world.SixTile): action_adder(actions, "z", "PORTAL", player.transport_to_nine, "Magic Portal") if isinstance(room, world.NineTile): action_adder(actions, "z", "PORTAL", player.transport_to_six, "Magic Portal") if isinstance(room, world.FiveTile): action_adder(actions, "r", "Guess", player.riddle, "Riddle") return actions
def pursue_player(self, player_direction): self.r = randint(1,100) if self.r < self.pursuit: print("The {} is after you! Heading {}".format(self.name, player_direction)) room = world.tile_at(self.x, self.y) room.enemy_que.remove(self) direction = getattr(self, player_direction) direction() room = world.tile_at(self.x, self.y) room.enemy_que.append(self)
def pursue_player(self, player_direction): self.r = randint(1,100) if self.r < self.pursuit: print("The {} is after you! Heading {}".format(self.name, player_direction)) room = world.tile_at(self.x, self.y) room.enemy_que.remove(self) direction = getattr(self, player_direction) direction() room = world.tile_at(self.x, self.y) room.enemy_que.append(self)
def enfieldattack(self): room = world.tile_at(self.x, self.y) enemy = room.enemy r1 = random.random() r2 = random.random() if self.enfield_loaded > 0: print("") print("You fire your enfield at the enemy.") self.enfield_loaded -= 1 if r1 < 0.2: print("You miss.") elif r1 < 0.8: enemy.hp -= items.Enfield().damage if not enemy.is_alive(): print("The soldier sinks to the ground. Mortally wounded.") else: if r2 > 0.5: print("You hit the soldier in the arm.") else: print("You hit the soldier in the lower torso.") else: enemy.hp -= 100 print("The soldier sinks to the ground. Mortally wounded") else: print("You need to reload!")
def play(): print("Escape from Cave Terror!") player = Player() while True: room = world.tile_at(player.x, player.y) print(room.intro_text()) if room.vicrory() == True: break action_input = get_player_command().lower() if action_input == 'n': player.move_north() elif action_input == 's': player.move_south() elif action_input == 'e': player.move_east() elif action_input == 'w': player.move_west() elif action_input == 'i': player.print_inventroy() elif action_input == 'q': print('You exied the game') break else: print("Invalid action!")
def loot_corpse(self): room = world.tile_at(self.x, self.y) print("You search the dead {}".format(room.enemy.name)) for bad_guy in room.enemy_que: if bad_guy.gold > 0: print("You find {} gold on the dead {}".format(bad_guy.gold, bad_guy.name)) self.gold += bad_guy.gold bad_guy.gold = 0 for bad_guy in room.enemy_que: if bad_guy.possessions == []: print("...and find nothing on the {}".format(bad_guy.name)) else: print("After more searching you find on the {}:".format(bad_guy.name)) for i, item in enumerate(bad_guy.possessions, 1): print("{} - {}".format(i, item)) try: choice = raw_input("Take it (a)ll or select the number to take: ") if choice in ['a','A']: self.inventory.extend(bad_guy.possessions) print("You picked up: ") print(", ".join([str(x)for x in bad_guy.possessions])) bad_guy.possessions = [] else: self.inventory.append(bad_guy.possessions[int(choice)-1]) print("You picked up {}.".format(bad_guy.possessions[int(choice)-1])) bad_guy.possessions.remove(bad_guy.possessions[int(choice)-1]) except(ValueError, IndexError): print("Invalid choice")
def play(): print("Escape from Cave Terror!") world.parse_world_dsl() player = Player() while player.is_alive() and not player.victory: room = world.tile_at(player.x, player.y) print(room.intro_text()) room.modify_player(player) if player.is_alive() and not player.victory: choose_action(room, player) elif not player.is_alive(): print("Your journey has come to an early end!") if action_input in ['n', 'N']: player.move_north() elif action_input in ['s', 'S']: player.move_south() elif action_input in ['e', 'E']: player.move_east() elif action_input in ['w', 'W']: player.move_west() elif action_input in ['i', 'I']: player.print_inventory() elif action_input in ['a', 'A']: player.attack() elif action_input in ['h', 'H']: player.heal() else: print("Invalid action!")
def drop_weapon(self): room = world.tile_at(self.x, self.y) for i, item in enumerate(self.weapons, 1): print(str(i) + ".", item) itemDropped = False while not itemDropped: choice = input( "Drop weapon (press '0' to cancel, 'a' to drop all): ") try: if choice == 'a': for item in self.weapons: room.items.append(item) print("Dropping the {}...".format(item)) self.weapons = [] self.weapon = None elif choice != '0': item = self.weapons[int(choice) - 1] if item == self.weapon: self.weapon = None self.weapons.remove(item) room.items.append(item) itemDropped = True except (ValueError, IndexError): print("That's not a valid choice!") print(Fore.CYAN + room.describe())
def heal(self): if len(self.consumables) == 0: print("Nothing to heal with.") else: print("Heal with which item?") for i, item in enumerate(self.consumables, 1): print(str(i) + ".", item) itemChosen = False while not itemChosen: choice = input( "Enter item number from the list above ('0' to cancel, 'a' to use all): " ) try: if choice == 'a': for item in self.consumables: print("Yum, {}.".format(item)) self.health = min(self.max_health, self.health + item.healing) self.consumables = [] elif choice != '0': print("Yum, {}.".format(item)) item = self.consumables[int(choice) - 1] self.health = min(self.max_health, self.health + item.healing) self.consumables.remove(item) itemChosen = True print("Your HP is now {}.".format(self.health)) except (ValueError, IndexError): print("That's not a valid choice!") room = world.tile_at(self.x, self.y) print(Fore.CYAN + room.describe())
def take_item(self): room = world.tile_at(self.x, self.y) if len(room.items) == 0: print("No items to take!") else: for i, item in enumerate(room.items, 1): print(str(i) + ".", item) itemChosen = False while not itemChosen: choice = input("Take item ('0' to cancel, 'a' to take all): ") try: if choice == 'a': roomitems = [x for x in room.items] for item in roomitems: print("Grabbing the {}...".format(item)) if self.move_to_inventory(item): room.items.remove(item) elif choice != "0": item = room.items[int(choice) - 1] if self.move_to_inventory(item): room.items.remove(item) itemChosen = True except (ValueError, IndexError): print("That's not a valid choice!") print(Fore.CYAN + room.describe())
def use_item(self): # usable items that counteract environmental hazards. # so far, only gas neutralizer and dust mask... room = world.tile_at(self.x, self.y) if len(self.objects) == 0: print("Got nothin' to use.") else: print("Available items:") for i, item in enumerate(self.objects, 1): print(str(i) + ".", item) itemChosen = False while not itemChosen: choice = input("Use item (0 to cancel): ") try: item = self.objects[int(choice) - 1] if isinstance(item, items.GasNeutralizer) and room.gas: print( "The poison gas in this room has been neutralized." ) room.gas = 0 del self.objects[int(choice) - 1] elif isinstance(item, items.DustMask) and room.fartsmell: print( "Your dust mask successfully counteracts the suffocating shit odor in this room. You can breathe again!" ) room.fartsmell = 0 del self.objects[int(choice) - 1] else: print( "That item seems to have no effect. You don't feel so good." ) itemChosen = True except ValueError: print("That's not a valid choice!!") print(Fore.CYAN + room.describe())
def loot_enemy(self): room = world.tile_at(self.x, self.y) enemy = room.enemy if enemy.items: for i, item in enumerate(enemy.items, 1): print(str(i) + ".", item) itemLooted = False while not itemLooted: choice = input("Loot item ('0' to cancel, 'a' to loot all): ") try: if choice == 'a': enemyitems = [x for x in enemy.items] for item in enemyitems: print("You looted the {}.".format(item)) if self.move_to_inventory(item): enemy.items.remove(item) elif choice != '0': print("You looted the {}!".format(item)) item = enemy.items[int(choice) - 1] if self.move_to_inventory(item): enemy.items.remove(item) itemLooted = True except (ValueError, IndexError): print("Invalid choice!") print(Fore.YELLOW + room.describe())
def attack(self): best_weapon = self.most_powerful_weapon() room = world.tile_at(self.x, self.y) enemy = room.enemy print("You use {} against {}!".format(best_weapon.name, enemy.name)) enemy.hp -= best_weapon.damage if not enemy.is_alive(): print("You killed {}!".format(enemy.name)) else: print("{} HP is {}.".format(enemy.name, enemy.hp))
def drop_item(self): room = world.tile_at(self.x, self.y) for i, item in enumerate(self.inventory, 1): print("{} - {}".format(i, item)) choice = raw_input("Select item to drop: ") try: room.ground.append(self.inventory[int(choice)-1]) print("You dropped: {}".format(self.inventory[int(choice)-1])) self.inventory.remove(self.inventory[int(choice)-1]) except(ValueError, IndexError): print("Invalid choice")
def attack(self): best_weapon = self.most_powerful_weapon() room = world.tile_at(self.x, self.y) for bad_guy in room.enemy_que: if bad_guy.is_alive(): print("You used {} againt {}!".format(best_weapon, bad_guy.name)) bad_guy.hp -= best_weapon.damage if not bad_guy.is_alive(): print("You kill {}!".format(bad_guy.name)) else: print("{} HP is {}. ".format(bad_guy.name, bad_guy.hp)) break
def get_item(self): room = world.tile_at(self.x, self.y) getable_items = [item for item in room.ground if item.takeable == True] for i, item in enumerate(getable_items, 1): print("{} - {}".format(i, item)) choice = raw_input("Select item to pick up: ") try: self.inventory.append(getable_items[int(choice)-1]) print("You picked up: {}".format(getable_items[int(choice)-1])) room.ground.remove(getable_items[int(choice)-1]) except(ValueError, IndexError): print("Invalid choice")
def get_available_actions(room, player): actions = OrderedDict() print("Choose an action: ") if player.inventory: action_adder(actions, 'i', player.print_inventory, "Print inventory") if isinstance(room, world.TraderTile): action_adder(actions, 't', player.trade, "Trade") if isinstance(room, world.EnemyTile) and room.enemy.is_alive(): action_adder(actions, 'a', player.attack, "Attack") else: if world.tile_at(room.x, room.y - 1): action_adder(actions, 'n', player.move_north, "Go north") if world.tile_at(room.x, room.y + 1): action_adder(actions, 's', player.move_south, "Go south") if world.tile_at(room.x + 1, room.y): action_adder(actions, 'e', player.move_east, "Go east") if world.tile_at(room.x - 1, room.y): action_adder(actions, 'w', player.move_west, "Go west") if player.hp < 100: action_adder(actions, 'h', player.heal, "Heal") return actions
def flee(self): flee_choices = [] room = world.tile_at(self.x, self.y) if world.tile_at(room.x, room.y-1): flee_choices.append("move_north") if world.tile_at(room.x, room.y+1): flee_choices.append("move_south") if world.tile_at(room.x+1, room.y): flee_choices.append("move_east") if world.tile_at(room.x-1, room.y): flee_choices.append("move_west") percent_chance = 1/len(flee_choices) r = random.random() for x in range (len(flee_choices)): if r < percent_chance: flee_direction = flee_choices[x] break else: percent_chance += percent_chance fleeNow = getattr(self, flee_direction) print("You fled the monster heading {}!".format(flee_direction[5:])) for bad_guy in room.enemy_que: bad_guy.pursue_player(flee_direction) fleeNow()
def trade(self): room = world.tile_at(self.x, self.y) room.check_if_trade(self)