What have you got, and what can you see?
So far there are three items in this new world:
But you cannot see the items in the room, nor can you check what you have in your pockets.
For the former, we return to the Room class.
In the initialisation code, a new list is added which contains the items present in the room.
self.item = []
This is not filled because the room may be loaded to determine the available exits during the movement action, and as the character is leaving the room, the contents are of no interest.
The items are added using the load_contents method.
def load_contents(self,acursor):
sql="select itemID, itemName, itemDescription, itemValue from items where itemRoomID=%s"
roomID=(str(self.roomID),)
acursor.execute(sql,roomID)
myresult = acursor.fetchall()
for x in myresult:
newitem=Item(x[0],x[1],x[2],x[3])
self.items.append(newitem)
def contents(self):
result="Items:" +str(len(self.items)) +"\n"
if len(self.items)>0:
result="The room contains the following: \n"
for anItem in self.items:
result+=anItem.get_name()
result+="\n"
else:
result="There are no items in this room"
return result
A call is made to this function in the get_details(self) function.