import items, enemies, actions, world

class MapTile:

    def adjacent_moves(self):
        """Returns all move actions for adjacent tiles."""
        moves =[]
        if world.tile_exists(self.x + 1, self.y):
            moves.append(actions.MoveEast())
        if world.tile_exists(self.x - 2,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

    def available_actions(self):
        moves = self.adjacent_moves()
        moves.append(actions.ViewInventory())

        return moves
    
    
    def __init__(self, x, y):
        self.x = x
        self.y = y

def intro_text(self):
    raise NotImplementedError()

class StartingRoom(MapTile):
    def intro_text(self):
        return """
        You find yourself in a cave with a flickering tourch on the wall.
        You can make out four paths. each equally as dark and foreboding.
        """
    def modfiy_player(self,player):
        #room has no action on player
        pass

class LootRoom(MapTile):
    def __init__(self, x, y, item):
        self.iitem = item
        super().__init__(x,y)

    def add_loot(self,player):
        player.inventory.append(self.item)

    def modify_player(self,player):
        self.add_loot(player)
class EnemyRoom(MapTile):
    def __init__(self, x, y,enemy):
        self.enemy =enemey
        super().__init__(x,y)

    def modify_player(self,the_player):
        if self.senemy.is_alive():
            the_player.hp = the_player.hp -self.enemy.damage
            print("Enemy does {} damage. You have {} hp remaining.".format(self.enemy.damage,the_player.hp))

    def available_actions(self):
        if self.enemy.is_alive():
            return [action.Flee(tile=self),actions.Attack(enemy= self.enemy)]
        else:
            return self.adjacent_moves()
                    
    
class GiantSpiderRoom(EnemyRoom):
    def __init__(self, x, y):
        super().__init__(x,y, enemies.GiantSpider())

    def intro_text(self):
        if self.enemy.is_allive():
            return """
            A giant spider jumps down from its web in front of you!
            
            """
        else:
            return """
            The corpse of a dead spider rots on the ground.
            """
class FindDaggerRoom(LootRoom):
    def __init__(self, x, y):
        super().__init__(x,y, items.Dagger())

    def intro_text(self):
        return """
        You notice somthing shiney in the corner; its a dagger!
        You pick it up
        """
class LeaveCaveRoom(MapTile):
    def intro_text(self):
        return """
        you see a bright light in the distance
        ...
        it grows as you approach,
        its sunlight!
        Victory is Yours!
        """

    def modify_player(self, player):
        player.victory = True

    
            

    





