0

Un método da error por argumento faltante pero esto no es cierto:

from time import sleep
from os import system

class labyrinth:
    map_matrix =\
    [
            [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            [1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
            [1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1],
            [1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1],
            [1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1],
            [1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1]
    ]

    map_start = [0, 2]
    map_end = [9, 8]
    map_with_player = None

    def player_in_map(self, player):
        self.map_with_player = self.map_matrix
        self.map_with_player[player.position[0]][player.position[1]] = 2

    def formated_map_print(self):
        counter = 0
        while counter < len(self.map_with_player):
            print(map_with_player[counter], "\n")
            counter += 1

class player:
    player_position = [0, 2]

    def can_move_up(self, map):
        if map.map_matrix[self.player_position[0] - 1][self.player_position[1]] == 0:
            return True
        else:
            return False

    def can_move_down(self, map):
        if map.map_matrix[self.player_position[0] + 1][self.player_position[1]] == 0:
            return True
        else:
            return False

    def can_move_right(self, map):
        if map.map_matrix[self.player_position[0]][self.player_position[1] + 1] == 0:
            return True
        else:
            return False

    def can_move_left(self, map):
        if map.map_matrix[self.player_position[0]][self.player_position[1] - 1] == 0:
            return True
        else:
            return False

    def move_up(self, map):
        if map.map_matrix[self.player_position[0] - 1][self.player_position[1]] == 0:
            self.player_position[0] -= 1

    def move_down(self, map):
        if map.map_matrix[self.player_position[0] + 1][self.player_position[1]] == 0:
            self.player_position[0] += 1

    def move_right(self, map):
        if map.map_matrix[self.player_position[0]][self.player_position[1] + 1] == 0:
            self.player_position[1] += 1

    def move_left(self, map):
        if map.map_matrix[self.player_position[0]][self.player_position[1] - 1] == 0:
            self.player_position[1] -= 1

my_labyrinth = labyrinth
my_player = player

while True:
    my_labyrinth.player_in_map(my_player) # Error

    system("cls")

    my_labyrinth.formated_map_print()

    sleep(1)

Dice que falta el argumento player pero si se lo estoy pasando.

1
  • nop, el error es cierto y tiene toda la razón. Lo que tú debess hacer es my_labyrinth = labyrinth() necesitas llamar a la clase
    – Christian
    el 2 nov. 2021 a las 1:05

1 respuesta 1

0

Ciertamente, le estás dando un argumento a my_labyrinth.player_in_map, pero en realidad espera que le des dos argumentos. Esto porque no has inicializado el objeto en sí (sólo estás llamando a sus métodos), y entonces se esperaría que agregaras dos argumentos en vez de uno: self y player. De hecho, tu programa llega a la conclusión de que estás definiendo self, no player.

A juzgar por tu código, creo que sería mejor reemplazar estas líneas:

my_labyrinth = labyrinth
my_player = player

por estas otras:

my_labyrinth = labyrinth()
my_player = player()

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.