
class TaulerVaixells:

    def __init__(self, dim = 5):
        self.num_tirades = 0
        self.__llista_caselles = []
        for _ in range(dim):
            self.__llista_caselles.append(['-'] * dim)

    def dimensio(self):
        return len(self.__llista_caselles)

    def __getitem__(self, posicio):
        x, y =  posicio
        return self.__llista_caselles[x][y]

    def afegeix_vaixell_H(self, posicio, n):
        x, y =  posicio
        for i in range(n):
            self.__llista_caselles[x+i][y] = 'V'
            
    def afegeix_vaixell_V(self, posicio, n):
        x, y =  posicio
        for i in range(n):
            self.__llista_caselles[x][y+i] = 'V'

    def dispara(self, posicio):
        self.num_tirades = self.num_tirades + 1
        x, y =  posicio
        if self.__llista_caselles[x][y] == 'V':
            self.__llista_caselles[x][y] = 'X'
