Advertisement
kenadams53

Character Object Kens Game

Aug 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. # Character object for kens Game, has Friend and Enemy as subclasses
  2. '''
  3. See pastebin for code:
  4. Kens Game main: https://pastebin.com/NHu4SGA0 # contains description of the game
  5. Room object: https://pastebin.com/Mn1HecX6
  6. Character object: https://pastebin.com/m6WJQNn5
  7. Item object: https://pastebin.com/GAirfZ5B
  8. '''
  9.  
  10. class Character(): # Character Object Kens Game
  11.  
  12. # Create a character
  13. def __init__(self, char_name, char_description):
  14. self.name = char_name
  15. self.description = char_description
  16. self.conversation = None
  17.  
  18. # Describe this character
  19. def describe(self):
  20. print( self.name + " is here!" )
  21. print( self.description + "\n" )
  22.  
  23. # Set what this character will say when talked to
  24. def set_conversation(self, conversation):
  25. self.conversation = conversation
  26.  
  27. # Talk to this character
  28. def talk(self):
  29. if self.conversation is not None:
  30. print("[" + self.name + " says]: " + self.conversation)
  31. else:
  32. print(self.name + " doesn't want to talk to you")
  33.  
  34. # Fight with this character
  35. def fight(self, combat_item):
  36. print(self.name + " doesn't want to fight with you")
  37. return True
  38.  
  39. def talk_back(self):
  40. if self.conversation is not None:
  41. print(self.name + "I think you are too smelly")
  42.  
  43. class Enemy(Character):
  44. def __init__(self, char_name, char_description):
  45. super().__init__(char_name, char_description)
  46. self.weakness = None
  47. self.noFights = 0
  48.  
  49. def set_weakness(self, weakness):
  50. self.weakness = weakness
  51.  
  52. def get_weakness(self):
  53. print( self + " has weakness " + self.weakness)
  54.  
  55. # Describe Enemy character
  56. def describe(self):
  57. print( "Enemy " + self.name + " is here!" )
  58. print( self.description + "\n" )
  59.  
  60. def fight(self, combat_item):
  61. if combat_item == self.weakness:
  62. print("You fend " + self.name + " off with the " + combat_item )
  63. return True
  64. else:
  65. print(self.name + " crushes you, puny adventurer")
  66. return False
  67.  
  68. class Friend(Character):
  69.  
  70. def __init__(self, char_name, char_description):
  71. super().__init__(char_name, char_description)
  72. self.has_item = None
  73.  
  74. def set_has_item(self, this_item):
  75. self.has_item = this_item
  76.  
  77. def get_has_item(self):
  78. print( self + " has item " + self.has_item)
  79.  
  80. # Describe Friend character
  81. def describe(self):
  82. print( "Friend " + self.name + " is here!" )
  83. print( self.description)
  84. print(self.name + " has " + self.has_item + "\n")
  85.  
  86. def hug(self):
  87. print(self.name + " hugs you back!")
  88.  
  89. # What other methods could your Friend class have?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement