Advertisement
TonyMo

character.py

Mar 12th, 2021
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. # character.py
  2. class Character():
  3.  
  4.     # Create a character
  5.     def __init__(self, char_name, char_description):
  6.         self.name = char_name
  7.         self.description = char_description
  8.         self.conversation = None
  9.  
  10.     # Describe this character
  11.     def describe(self):
  12.         print( self.name + " is here!" )
  13.         print( self.description )
  14.  
  15.     # Set what this character will say when talked to
  16.     def set_conversation(self, conversation):
  17.         self.conversation = conversation
  18.  
  19.     # Talk to this character
  20.     def talk(self):
  21.         if self.conversation is not None:
  22.             print("[" + self.name + " says]: " + self.conversation)
  23.         else:
  24.             print(self.name + " doesn't want to talk to you")
  25.  
  26.     # Fight with this character
  27.     def fight(self, combat_item):
  28.         print(self.name + " doesn't want to fight with you and your", combat_item,"!")
  29.         return True
  30.  
  31.  
  32. """
  33. * Examine the Character class inside character.py to find the name of the method that sets the conversation attribute.
  34.        method = set_conversation, attribute =  conversation
  35. * Add code to your program to call this method and give Dave a line of dialogue.
  36.        See character_test.py dave.talk etc
  37. * Add code to your program to call a different method that talks to Dave.
  38.        Add to fight dialogue here and and add dave.fight()
  39. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement