Exemplo n.º 1
0
 def adjacent_moves(self):
     moves = []
     if world.tile_exists(self.x + 1, self.y):
         moves.append(actions.MoveEast)
     if world.tile_exists(self.x - 1, self.y):
         moves.append(actions.MoveWest)
     if world.tile_exists(self.x, self.y - 1):
         moves.append(actions.MoveNorth)
     if world.tile_exists(self.x, self.y + 1):
         moves.append(actions.MoveSouth)
     return moves
Exemplo n.º 2
0
 def attack(self):
     equipped_weapon = self.equipped_weapon
     enemy = world.tile_exists(self.location_x, self.location_y).enemy
     if equipped_weapon == None:
         return "You need a weapon first!"
     if random.randint(0, 100) >= enemy.block:
         enemy_resistance = (100 - enemy.armour)
         dealt_damage = int(round((enemy_resistance * equipped_weapon.damage) / 100))
         enemy.hp -= dealt_damage
         if not enemy.is_alive():
             return "You hit {} with {}, dealing {} damage - a killing blow!".format(enemy, equipped_weapon, dealt_damage)
         else:
             return "You hit {} with {}, dealing {} damage!\n{} now has {} HP.".format(enemy, equipped_weapon, dealt_damage, enemy, enemy.hp) + "\n" + world.tile_exists(self.location_x, self.location_y).enemy_attack(self)
     return "Your attack misses!\n{} still has {} HP.".format(enemy, enemy.hp) + "\n" + world.tile_exists(self.location_x, self.location_y).enemy_attack(self)
Exemplo n.º 3
0
 def move(self, dx, dy):
     self.location_x += dx
     self.location_y += dy
     return world.tile_exists(self.location_x, self.location_y).show_room_text()
Exemplo n.º 4
0
 def look_around(self):
     return world.tile_exists(self.location_x, self.location_y).view_tile_inventory()
Exemplo n.º 5
0
 def flee(self):
     moves = world.tile_exists(self.location_x, self.location_y).adjacent_moves()
     r = random.randint(0, len(moves) - 1)
     return world.tile_exists(self.location_x, self.location_y).enemy_attack(self) + "\n" + self.do_action(moves[r])
Exemplo n.º 6
0
 def sell(self, item):
     return world.tile_exists(self.location_x, self.location_y).sell_item(self, item)
Exemplo n.º 7
0
 def buy(self, item):
     return world.tile_exists(self.location_x, self.location_y).buy_item(self, item)
Exemplo n.º 8
0
 def drop(self, item):
     return world.tile_exists(self.location_x, self.location_y).drop_item(self, item)
Exemplo n.º 9
0
 def pick_up(self, item):
     return world.tile_exists(self.location_x, self.location_y).pick_up_item(self, item)