Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Room():
- def __init__(self, room_name):
- self.name = room_name
- self.description = None
- self.character = None
- self.linked_rooms ={}
- def set_name(self, room_name):
- self.name = room_name
- def set_description(self, room_description):
- self.description = room_description
- def get_description(self):
- return(self.description)
- def describe(self):
- print(self.description)
- def get_name(self):
- return (self.name)
- def set_character(self, character):
- self.character = character
- def get_character(self):
- return self.character
- def linked_room(self, room_to_link, direction):
- self.linked_rooms[direction] = room_to_link
- print(self.name + " linked rooms : " + repr(self.linked_rooms))
- def get_details(self):
- for direction in self.linked_rooms:
- room = self.linked_rooms[direction]
- print(" The " + room.get_name() + " is " + direction)
- def move(self, direction):
- if direction in self.linked_rooms:
- return self.linked_rooms[direction]
- else:
- print("you can't go that way")
- return self
- ------------------------------------------------------
- from room import Room
- from character import Character
- from character import Enemy
- kitchen = Room("Kitchen")
- kitchen.set_description("A dirty room full of rotten food and flies")
- kitchen.describe()
- dining = Room("Dining hall")
- dining.set_description("A wonderfull and large room for christmas dinner")
- dining.describe()
- ballroom = Room("Ballroom")
- ballroom.set_description("A wonderfull room for dancing and music")
- ballroom.describe()
- kitchen.linked_room(dining, "South")
- ballroom.linked_room(dining, "West")
- dining.linked_room(kitchen, "North")
- dining.linked_room(ballroom, "East")
- kitchen.get_details()
- ballroom.get_details()
- dave = Enemy("Dave", "A smelly zombie")
- dave.describe()
- dave.talk()
- current_room = kitchen
- dining.set_character(dave)
- while True:
- print("\n")
- current_room.get_details()
- inhabitant = current_room.get_character()
- if inhabitant is not None:
- inhabitant.describe()
- command = input("> ")
- current_room = current_room.move(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement