Hi, I´m wondering how i can append newly created objects to a list by using subclass.I have come this far:
class Room(object):
def __init__(self,name):
self.name=str(name)
self.hazard = self.empty
#def __str__(self):
# return self.name
def pits(self,antal):
pit=1
while pit<antal:
assert self.hazard == self.empty
self.hazard=self.Pits
# return self.hazard
def bats(self,antal):
bat=1
while bat<antal:
assert self.hazard == self.empty
self.hazard=self.Bats
#return self.hazard
def wumpus(self,antal=1):
self.wumpus= random.choice(cave_map)
class Game(Room):
def __init__(self):
self.map=[]
for i in range(0,20):
cave=Room(i+1)
self.map.append(cave)
def cave_map(self):
vertical_list=self.map[:]
horizontal_list=self.map[:]
shuffle(vertical_list)
for k in range len(vertical_list):
while vertical_list[i]==horizontal_list[i]:
shuffle(horizontal_list)
I am trying to create 20 room objects through the subclass Game and the append it to self.map but it doesn´t work, Please tell me what i am doing wrong?