def available_actions(self, player): if self.enemy.is_alive(): moves = [actions.Flee(tile=self), actions.Attack(enemy=self.enemy)] if player.has_potion(): moves.append(actions.UsePotion()) return moves else: moves = self.adjacent_moves() moves.append(actions.ViewInventory()) moves.append(actions.ViewCurrency()) if player.has_potion(): moves.append(actions.UsePotion()) return moves
def available_actions(self, player): moves = self.adjacent_moves() moves.append(actions.ViewInventory()) moves.append(actions.ViewCurrency()) if player.has_potion(): moves.append(actions.UsePotion()) moves.append(actions.EnterShop()) return moves
def available_actions(self, player): #Returns all of the available actions in this room moves = self.adjacent_moves() moves.append(actions.ViewInventory()) moves.append(actions.ViewCurrency()) if player.has_potion(): moves.append(actions.UsePotion()) return moves
def available_actions(self, player): moves = self.adjacent_moves() moves.append(actions.ViewInventory()) moves.append(actions.ViewCurrency()) if player.has_potion(): moves.append(actions.UsePotion()) if self.item.takeable: moves.append(actions.Take(item=self.item)) return moves
def generic_moves(self, player): """Returns the standard moves that are available in every room. These include: -movement options -choosing weapons -viewing inventory -using potions -looking around at objects in room Args: player: an instance of the player class Returns: moves: dictionary mapping nouns to the verbs that can be applied to them. avail_actions: a list of actions from actions.py descriptors: dictionary mapping nouns to their respective descriptors allow adjectives in commands """ moves = dict() # the verbs associated with each noun descriptors = dict() # the adjectives associated with each noun avail_actions = [] # the availble actions from actions.py # determine the possible moves to other tiles (ie, move west) if world.tile_exists(self.x + 1, self.y): moves, avail_actions = self.update(moves, avail_actions, actions.MoveEast()) if world.tile_exists(self.x - 1, self.y): moves, avail_actions = self.update(moves, avail_actions, actions.MoveWest()) if world.tile_exists(self.x, self.y - 1): moves, avail_actions = self.update(moves, avail_actions, actions.MoveNorth()) if world.tile_exists(self.x, self.y + 1): moves, avail_actions = self.update(moves, avail_actions, actions.MoveSouth()) # look at inventory moves, avail_actions = self.update(moves, avail_actions, actions.ViewInventory()) for potion in player.available_potions(): moves, avail_actions = self.update(moves, avail_actions, actions.UsePotion(potion=potion, tile=self, enemy=None)) # choose or change weapon moves, avail_actions = self.update(moves, avail_actions, actions.ChangeWeapon()) moves, avail_actions = self.update(moves, avail_actions, actions.Look(noun=None, tile=self)) for item in self.look_at: moves, avail_actions = self.update(moves, avail_actions, actions.Look(noun=item, tile=self)) descriptors[item] = self.look_at[item] return moves, avail_actions, descriptors
def available_actions(self, player): """Returns all of the available actions in a room containing an enemy""" moves, avail_actions, descriptors = self.generic_moves(player) movements = ["west", "east", "north", "south"] if self.enemy.is_alive(): for direction in movements: if direction in moves: moves.pop(direction) moves, avail_actions = self.update(moves, avail_actions, actions.Flee(noun=player.prev_tile, enemy=self.enemy, direction=player.prev_tile)) moves, avail_actions = self.update(moves, avail_actions, actions.Flee(noun=None, enemy=self.enemy, direction=player.prev_tile)) moves, avail_actions = self.update(moves, avail_actions, actions.Flee(noun=self.enemy.name, enemy=self.enemy, direction=player.prev_tile)) moves, avail_actions = self.update(moves, avail_actions, actions.ViewOrbs()) for potion in player.available_potions(): moves, avail_actions = self.update(moves, avail_actions, actions.UsePotion(potion=potion, tile=self, enemy=self.enemy)) for orb in items.Orb.orb_types(): moves, avail_actions = self.update(moves, avail_actions, actions.Cast(orb=orb)) moves, avail_actions = self.update(moves, avail_actions, actions.Attack(enemy=self.enemy, tile=self, weapon=None)) a = actions.Attack(enemy=self.enemy, tile=self, weapon=None) noun, verbs = a.add_actions() weapons = player.available_weapons() for weapon in weapons: moves[weapon.name] = verbs return moves, avail_actions, descriptors