Advertisement
richwhilecooper

PLAYER CLASS EXTENDED with implementation

Nov 29th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. ###NEW PLAYER CLASS AND HOW I'M IMPLEMENTING IT
  2. ###Player Class
  3.  
  4. class Player():
  5.     def __init__(self,player_name):
  6.         self.name = player_name
  7.         self.health = None
  8.         self.inventory = []
  9.  
  10.     def set_inventory(self,inventory_list):
  11.         self.inventory = inventory_list
  12.  
  13.     def get_inventory(self):
  14.         return self.inventory
  15.  
  16.     def set_health(self,health_points):
  17.         self.health = health_points
  18.  
  19.     def get_health(self):
  20.         return self.health
  21.  
  22.     def describe(self):
  23.         print ("You name is, ", self.name)
  24.         print ("You are carrying:")
  25.         for item in self.inventory:
  26.             print (item[0], item[1])
  27.         print ()
  28.         print ("Your health is :", self.health)
  29.  
  30.     def set_inv_item(self,inv_item):
  31.         self.item = inv_item
  32.  
  33.     def get_inv_item(self):
  34.         return self.item
  35.  
  36.     def check_inventory(self,item):
  37.         in_inv = False
  38.         for thing in self.inventory:
  39.             if item in thing[0]:
  40.                 in_inv = True
  41.                 break
  42.         return in_inv
  43.  
  44. #####IMPLEMENMTATION IN MAIN... PARTIAL ONLY!
  45.     elif command =="Give":
  46.         inventory = protag.inventory
  47.         if inhabited is not None:
  48.             give_with= input("What will you give? >>> ")
  49.             protag.set_inv_item = give_with
  50.             in_invent = protag.check_inventory(give_with)
  51.             print (in_invent)
  52.             if in_invent == False:
  53.                 print ("You do not have",give_with,"!")
  54.             else:
  55.                 if inhabited.hug(give_with):
  56.                     print (inhabited.name, "rewards you with",inhabited.reward)
  57.                     inventory.append(inhabited.reward)                
  58.         else:
  59.             print ("As there is no-one to give to, you wave the",give_with,"in the air")
  60.             print ("It resolves nothing. You quickly tire of this pointless activity.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement