Cuando intento ejecutar el programa me aparece el error de:
line 26, in
if map_objets[POSITION_X] == coordinate_x and map_objets[POSITION_Y] == coordinate_y:
TypeError: 'int' object is not subscriptable"
y como soy un aprendiz autodidacta me encuentro sin maneras de buscar una posible solución que sirva a mi caso.
import os
import readchar
POSITION_X = 0
POSITION_Y = 0
MAP_WIDTH = 20
MAP_HEIGHT = 15
my_position = [4, 5]
map_objets = [[1, 3], [5, 8], [8, 9]]
while True:
# Draw_map
print("+" + "-" * MAP_WIDTH * 3 + "+")
for coordinate_y in range(MAP_HEIGHT):
print("|", end="")
for coordinate_x in range(MAP_WIDTH):
char_to_draw = " "
objet_in_cel = None
for map_objets in map_objets:
if map_objets[POSITION_X] == coordinate_x and map_objets[POSITION_Y] == coordinate_y:
char_to_draw = "o"
objet_in_cel = map_objets
if my_position[POSITION_X] == coordinate_x and my_position[POSITION_Y] == coordinate_y:
char_to_draw = "@"
if objet_in_cel:
map_objets.remove(objet_in_cel)
print(" {} ".format(char_to_draw), end="")
print("|")
print("+" + "-" * MAP_WIDTH * 3 + "+")
# ask user where he wants to move
direction = readchar.readchar()
if direction == "w":
my_position[POSITION_Y] -= 1
my_position[POSITION_Y] %= MAP_HEIGHT
elif direction == "s":
my_position[POSITION_Y] += 1
my_position[POSITION_Y] %= MAP_HEIGHT
elif direction == "a":
my_position[POSITION_X] -= 1
my_position[POSITION_X] %= MAP_WIDTH
elif direction == "d":
my_position[POSITION_X] += 1
my_position[POSITION_X] %= MAP_WIDTH
elif direction == "q":
break
os.system('clear')