Thank you in advance
I am getting this TypeError: 'TreasureMap' object is not subscriptable.
This is my code
I am getting this TypeError: 'TreasureMap' object is not subscriptable.
This is my code
i = 0 k = 0 class TreasureMap: def __init__(self , map ): self.map = map self.rows = len(map) self.columns = len(hiddenmap1[2]) def create_hunter_map(self): empty_map = [] for i in range(self.rows): row = [] for k in range(self.columns): row.append('-') empty_map.append(row) return empty_map #return [["-" for _ in range(self.columns)] for _ in range(self.rows)] #ta row kai coloum einai ta simia pou dialego na paw #ftiaxno prwta to updated xarti #meta ftiaxno xarti opou tha lipouin tixon thisauroi def update_hunter_map( self , Hmap , location): row , column = location if self.map[row][column] == 'x': Hmap[row][column] = 'x' self.map[row][column] = 'o' return 1 else: Hmap[row][column] = 'o' return 0 class TreassureHunter(): def __init__(self , name , map): self.name = name self.map = map self.h_map = treasure_map.create_hunter_map() self.treassures = 0 def move_on_map(self , location): row , column = location if self.map[row][column] == 'x': self.h_map[row][column] = 'x' self.treassures += 1 else: self.h_map[row][column] = 'o' #return self.h_map def check_status(self): print(f'{self.name} status') for row in self.h_map: print(' '.join(row)) print(f"βρέθηκαν {self.treassures} θησαυροίe") return self.h_map , self.treassures hiddenmap1=[['o','o','o','o','x'], ['o','x','x','o','x'], ['o','o','o','o','x']] treasure_map = TreasureMap(hiddenmap1) hunter_map = treasure_map.create_hunter_map() #updated_map = treasure_map.update_hunter_map(hunter_map ,[0,4]) Hunter1 = TreassureHunter('denis' , treasure_map) Hunter1.move_on_map([2,1]) Hunter1.check_status() Hunter1.move_on_map([0,0]) Hunter1.check_status() Hunter1.move_on_map([1,1]) Hunter1.check_status() Hunter1.move_on_map([0,3]) Hunter1.check_status() Hunter2 = TreassureHunter('Vagg' , treasure_map) Hunter2.move_on_map([1,1]) Hunter2.check_status()MY GOAL IT TO GET THIS RESULT
Output:Vaggstatus
Map
-----
-----
-o---
Acquired 0 treasures so far!
Vaggstatus
Map
----x
-----
-o---
Acquired 1 treasures so far!
Vaggstatus
Map
o---x
-----
-o---
Acquired 1 treasures so far!
Robstatus
Map
----o
-----
-----
Acquired 0 treasures so far!
Larz60+ write May-25-2024, 09:45 AM:
Duplicate posts have been soft deleted. Please post only once.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use BBCode tags on future posts.
Duplicate posts have been soft deleted. Please post only once.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use BBCode tags on future posts.