Advertisement
TonyMo

character.py

Mar 14th, 2021
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. # 3 4 3 3 was 3 2 OK , 3 6  38
  2. # ref  3 6 Aggregation .htm
  3.  
  4. class Character():
  5.  
  6.     # Create a character
  7.     def __init__(self, char_name, char_description):
  8.         self.name = char_name
  9.         self.description = char_description
  10.         self.conversation = None
  11.  
  12.     # Describe this character
  13.     def describe(self):
  14.         print( self.name + " is here!" )
  15.         print( self.description )
  16.  
  17.     # Set what this character will say when talked to
  18.     def set_conversation(self, conversation):
  19.         self.conversation = conversation
  20.  
  21.     # Talk to this character
  22.     def talk(self):
  23.         if self.conversation is not None:
  24.             print("[" + self.name + " says]: " + self.conversation)
  25.         else:
  26.             print(self.name + " doesn't want to talk to you")
  27.  
  28.     # Fight with this character
  29.     def fight(self, combat_item):
  30.         print(self.name + " doesn't want to fight with you!")
  31.         return True
  32.  
  33.  
  34. #  Enemy subclass to the superclass of Character
  35. class Enemy(Character):
  36.     def __init__(self, char_name, char_description):
  37.         super().__init__(char_name, char_description)
  38.         self.weakness = None
  39.  
  40.     # Add getter and setter methods to Enemy so that you can add a weakness for an enemy.
  41.     def set_weakness(self, item_weakness):
  42.         self.weakness = item_weakness
  43.  
  44.     def get_weakness(self):
  45.         return self.weakness
  46.     def fight(self, combat_item):
  47.         if combat_item == self.weakness:
  48.             print("You fend " + self.name + " off with the " + combat_item )
  49.             return True
  50.         else:
  51.             print(self.name + " crushes you and your",combat_item,"!")
  52.             return False
  53.  
  54.     def steal(self):
  55.         print("You steal from " + self.name)
  56.         # How will you decide what this character has to steal?
  57.  
  58. class Friend(Character):
  59.  
  60.     def __init__(self, char_name, char_description):
  61.  
  62.         super().__init__(char_name, char_description)
  63.         self.feeling = None
  64.  
  65.     def hug(self):
  66.         print(self.name + " hugs you back!")
  67.  
  68.     # What other methods could your Friend class have?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement