def test_room_paths(): center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") center.add_paths({'north': north, 'south': south}) assert_equal(center.go('north'), north) assert_equal(center.go('south'), south)
def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, you can go up.") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
from engine import Engine from room import Room north = Room("North Room", """This room is to the north of the center room. You can also reach the East and West rooms from here.""", ['kid\'s water floaties']) south = Room("South Room", """This room is to the south of the center room. You can also reach the East and West rooms from here.""") center = Room("Center Room", """This room is surrounded by 4 rooms. To the North, South, East and West.""", ['sword', 'chocolate bar', 'helmet']) east = Room("East Room", """This room is to the east of the center room. You can also reach the North and South rooms from here.""") west = Room("""West Room", "This room is to the west of the center room. You can also reach the North and South rooms from here.""", ['walkman', 'fanny pack']) north.add_paths({'down': center, 'center': center, 'east': east, 'west': west}) south.add_paths({'up': center, 'center': center, 'east': east, 'west': west}) center.add_paths({'north': north, 'south': south, 'east': east, 'west': west}) east.add_paths({'center': center, 'north': north, 'south': south}) west.add_paths({'center': center, 'north': north, 'south': south}) test_engine = Engine() test_engine.play(center)
This is Ten Forward. It is the recreational facility on the USS Enterprise, where officers, crew, and passengers can, um... recreate. """) ten_forward.add_items(['riker']) trois_quarters = Room("Troi's Quarters", """ You are in Troi's quarters. """) trois_quarters.add_items(['troi']) datas_quarters = Room("Troi's Quarters", """ You are in Data's quarters. """) datas_quarters.add_items(['data', 'spot']) hallway = Room("Hallway", """ You are in a hallway on board the USS Enterprise. """) ten_forward.add_paths({'south': hallway}) trois_quarters.add_paths({'west': hallway}) datas_quarters.add_paths({'east': hallway}) hallway.add_paths({'north': ten_forward, 'east': trois_quarters, 'west': datas_quarters}) class Game(object): def __init__(self): self.current_room = hallway self.inventory = ['microspanner'] self.game_over = False def change_room(self, direction): if (direction in self.current_room.paths.keys()): self.current_room = self.current_room.paths[direction]