Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Character object for kens Game, has Friend and Enemy as subclasses
- '''
- See pastebin for code:
- Kens Game main: https://pastebin.com/NHu4SGA0 # contains description of the game
- Room object: https://pastebin.com/Mn1HecX6
- Character object: https://pastebin.com/m6WJQNn5
- Item object: https://pastebin.com/GAirfZ5B
- '''
- class Character(): # Character Object Kens Game
- # Create a character
- def __init__(self, char_name, char_description):
- self.name = char_name
- self.description = char_description
- self.conversation = None
- # Describe this character
- def describe(self):
- print( self.name + " is here!" )
- print( self.description + "\n" )
- # Set what this character will say when talked to
- def set_conversation(self, conversation):
- self.conversation = conversation
- # Talk to this character
- def talk(self):
- if self.conversation is not None:
- print("[" + self.name + " says]: " + self.conversation)
- else:
- print(self.name + " doesn't want to talk to you")
- # Fight with this character
- def fight(self, combat_item):
- print(self.name + " doesn't want to fight with you")
- return True
- def talk_back(self):
- if self.conversation is not None:
- print(self.name + "I think you are too smelly")
- class Enemy(Character):
- def __init__(self, char_name, char_description):
- super().__init__(char_name, char_description)
- self.weakness = None
- self.noFights = 0
- def set_weakness(self, weakness):
- self.weakness = weakness
- def get_weakness(self):
- print( self + " has weakness " + self.weakness)
- # Describe Enemy character
- def describe(self):
- print( "Enemy " + self.name + " is here!" )
- print( self.description + "\n" )
- def fight(self, combat_item):
- if combat_item == self.weakness:
- print("You fend " + self.name + " off with the " + combat_item )
- return True
- else:
- print(self.name + " crushes you, puny adventurer")
- return False
- class Friend(Character):
- def __init__(self, char_name, char_description):
- super().__init__(char_name, char_description)
- self.has_item = None
- def set_has_item(self, this_item):
- self.has_item = this_item
- def get_has_item(self):
- print( self + " has item " + self.has_item)
- # Describe Friend character
- def describe(self):
- print( "Friend " + self.name + " is here!" )
- print( self.description)
- print(self.name + " has " + self.has_item + "\n")
- def hug(self):
- print(self.name + " hugs you back!")
- # What other methods could your Friend class have?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement