+ elif ans == 2:
+ # use the object according to its type
+ self.use_object (obj)
+ # if it cannot be picked up, try to use it anyway
+ else:
+ self.use_object (obj)
+
+ # this method uses the object first by calling the object use () method
+ # and then performing specific actions as necessary
+ def use_object (self, obj):
+ # if the object is a health potion
+ if isinstance (obj, gameobjects.HealthPotion) is True:
+ obj.use (self.butaba)
+ self.currentlevel.objects.remove (obj)
+ self.status_message = "You gained health"
+ # if the object is a chest
+ elif isinstance (obj, gameobjects.Chest) is True:
+ # if chest is locked, try to open it
+ if obj.locked is True:
+ # try opening the chest with every item 9the use () function
+ # of the chest determines if item is a key anyway
+ fittedkey = None
+ for invobj in self.butaba.inventory:
+ fittedkey = obj.use (invobj)
+ # if a key fits
+ if fittedkey is not None:
+ break
+ # if no key found
+ if fittedkey is None:
+ self.status_message = "No key found to open %s" % obj.text
+ # chest successfully unlocked
+ else:
+ self.status_message = "You unlocked the %s" % obj.text
+ # remove the key from inventory
+ self.butaba.inventory.remove (fittedkey)
+ # display the contents of the chest
+ else:
+ pass