Advertisement
johnpentyrch

item

May 4th, 2020
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. class Item():
  2.     def __init__(self,item_name):
  3.         self.name=item_name
  4.         self.description=None
  5.         self.powers = []
  6.  
  7.        
  8.     def set_description(self, item_description):
  9.         self.description = item_description
  10.        
  11.     def get_description(self):
  12.         return self.description
  13.  
  14.     def set_name(self, item_name):
  15.         self.name = item_name
  16.        
  17.     def get_name(self):
  18.         return self.name
  19.    
  20.     def add_power(self, power):
  21.         self.powers.append(power)
  22.        
  23.     def get_power(self):
  24.         return self.powers
  25.    
  26.     def describe(self):
  27.         print( self.description )
  28.        
  29.        
  30.     def get_details(self):
  31.         iname=self.name
  32.         print('\n',iname)
  33.         idescr=self.description
  34.         print(idescr)
  35.         for power in self.powers:
  36.             print( "This has " + power + " (power) " )
  37.  
  38. if __name__ == "__main__":
  39.    
  40.     s=Item('Sword')
  41.     s.set_description('shiny metal; I cut clean')
  42.     s.add_power('Kills trolls')
  43.     s.add_power('Opens locked chests')
  44.  
  45.  
  46.     s2=Item('Cloak')
  47.     s2.set_description('a shiny goldern cloak')
  48.     s2.add_power('makes you invisible')
  49.     s2.add_power('neutralises Dragons')
  50.  
  51.  
  52.     s.get_details()
  53.     s2.get_details()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement