Example #1
0
class TestRooms(unittest.TestCase):

    def setUp(self):
        self.dresser = Dresser()
        self.bed = Bed()
        self.lamp = Lamp()
        self.room = Room(name = "Room", objects = [self.dresser, self.bed, self.lamp], description = "A room.", exits={})
        
    def tearDown(self):
        pass


    def test_room_defaults(self):
        "Defaults are being passed correctly"
        self.assertEquals(self.room.name, "Room")
        self.assertEquals(self.room.objects, [self.dresser, self.bed, self.lamp])
        self.assertEquals(self.room.description, "A room.")
        self.assertEquals(self.room.exits, {})
    
    def test_room_look(self):
        "room.look() returns room.description"
        self.assertEquals(self.room.look(), self.room.description)

    def test_move_room(self):
        """Calling move should return the room object that is in that direction.  
        If the direction does not exist, an error should be thrown."""
        # existing direction
        other_room = Room(name='', objects=[], description='', exits={'north':self.room})
        self.room.exits['south'] = other_room
        self.assertEquals(self.room.move('south'), other_room)
        # direction that does not exist
        self.assertEquals(self.room.move('west'), "You cannot go that way.")
Example #2
0
 def setUp(self):
     self.dresser = Dresser()
     self.bed = Bed()
     self.lamp = Lamp()
     self.chair = Chair()
     self.room = Room(name="Room",
                      objects=[self.dresser, self.bed, self.lamp],
                      description="A room.",
                      exits={})
     self.southern_room = Room(name='',
                               objects=[],
                               description='',
                               exits={'north': self.room})
     self.room.exits['south'] = self.southern_room
Example #3
0
    def __init__(self):

        bed = Bed()
        lamp = UnreachableLamp()
        dresser = Dresser()
        chair = Chair()
        Bedroom = Room(name='Bedroom', objects=[bed, lamp, dresser], description='A homey room with blue wallpaper \
            and old-fashioned scenes hanging from brass frames.  There is a large four-poster against one wall \
            and a small dresser in the corner.', exits={})
        Closet = Room(name='Closet', objects=[chair], description='Significantly colder than the bedroom, \
            the closet has a slanted roof that only makes it feel more cramped', exits={})
        Bedroom.exits['west'] = Closet
        Closet.exits['east'] = Bedroom

        self.all_objs = [bed, lamp, dresser, chair]
        self.game = {'rooms': [Bedroom, Closet], 'inv': [], 'location': Bedroom}
Example #4
0
 def setUp(self):
     self.dresser = Dresser()
     self.bed = Bed()
     self.lamp = Lamp()
     self.chair = Chair()
     self.room = Room(name="Room", objects=[self.dresser, self.bed, self.lamp], description="A room.", exits={})
     self.southern_room = Room(name="", objects=[], description="", exits={"north": self.room})
     self.room.exits["south"] = self.southern_room
Example #5
0
 def test_equality(self):
     "Two rooms should be considered equal if they have the same name, description, objects, and exits"
     name, desc, exits = self.room.name, self.room.description, self.room.exits
     objs = [Dresser(), Lamp(), Bed()]
     other_room = Room(name, objs, desc, exits)
     # equal
     self.assertTrue(self.room == other_room)
     other_room.objects.pop()
     # not equal
     self.assertFalse(self.room == other_room)
    def __init__(self):

        bed = Bed()
        lamp = UnreachableLamp()
        dresser = Dresser()
        chair = Chair()
        Bedroom = Room(name='Bedroom',
                       objects=[bed, lamp, dresser],
                       description='A homey room with blue wallpaper \
            and old-fashioned scenes hanging from brass frames.  There is a large four-poster against one wall \
            and a small dresser in the corner.',
                       exits={})
        Closet = Room(name='Closet',
                      objects=[chair],
                      description='Significantly colder than the bedroom, \
            the closet has a slanted roof that only makes it feel more cramped',
                      exits={})
        Bedroom.exits['west'] = Closet
        Closet.exits['east'] = Bedroom

        self.all_objs = [bed, lamp, dresser, chair]
        self.game = {
            'rooms': [Bedroom, Closet],
            'inv': [],
            'location': Bedroom
        }
Example #7
0
class TestRooms(unittest.TestCase):
    def setUp(self):
        self.dresser = Dresser()
        self.bed = Bed()
        self.lamp = Lamp()
        self.chair = Chair()
        self.room = Room(name="Room", objects=[self.dresser, self.bed, self.lamp], description="A room.", exits={})
        self.southern_room = Room(name="", objects=[], description="", exits={"north": self.room})
        self.room.exits["south"] = self.southern_room

    def tearDown(self):
        pass

    def test_room_defaults(self):
        "Defaults are being passed correctly"
        self.assertEquals(self.room.name, "Room")
        self.assertEquals(self.room.objects, [self.dresser, self.bed, self.lamp])
        self.assertEquals(self.room.description, "A room.")
        self.assertEquals(self.room.exits, {"south": self.southern_room})

    def test_room_look(self):
        "room.look() returns room.description"
        self.assertEquals(self.room.look(), self.room.description)

    def test_move_room(self):
        """Calling move should return the room object that is in that direction.  
        If the direction does not exist, an error should be thrown."""
        # existing direction
        self.assertEquals(self.room.move("south", []), self.southern_room)
        # direction that does not exist
        self.assertEquals(self.room.move("west", []), "You cannot go that way.")

    def test_move_when_standing(self):
        "User should not be able to move locations when standing on something"
        # when chair is in user's inventory
        inv = [self.chair]
        self.chair.has_user = True
        self.assertEquals(self.room.move("south", inv), "You must climb down first.")
        # when chair is in the room
        self.room.objects.append(self.chair)
        self.assertEquals(self.room.move("south", []), "You must climb down first.")
        # but should succeed when the user gets down
        self.chair.has_user = False
        self.assertEquals(self.room.move("south", []), self.southern_room)

    def test_equality(self):
        "Two rooms should be considered equal if they have the same name, description, objects, and exits"
        name, desc, exits = self.room.name, self.room.description, self.room.exits
        objs = [Dresser(), Lamp(), Bed()]
        other_room = Room(name, objs, desc, exits)
        # equal
        self.assertTrue(self.room == other_room)
        other_room.objects.pop()
        # not equal
        self.assertFalse(self.room == other_room)
Example #8
0
 def setUp(self):
     closet = Dresser()
     closet.name = closet.id = 'closet'
     outer = Dresser()
     outer.id = outer.name = 'outer'
     chair = Chair()
     room = Room(name='room',
                 objects=[outer, chair],
                 exits={},
                 description='a room.')
     self.game = Game()
     self.game.game['rooms'] = [room]
     self.game.game['location'] = room
     self.game.game['inv'] = []
     self.game.all_objs = [outer, closet, chair]
     self.base = deepcopy(self.game)
Example #9
0
class TestRooms(unittest.TestCase):
    def setUp(self):
        self.dresser = Dresser()
        self.bed = Bed()
        self.lamp = Lamp()
        self.chair = Chair()
        self.room = Room(name="Room",
                         objects=[self.dresser, self.bed, self.lamp],
                         description="A room.",
                         exits={})
        self.southern_room = Room(name='',
                                  objects=[],
                                  description='',
                                  exits={'north': self.room})
        self.room.exits['south'] = self.southern_room

    def tearDown(self):
        pass

    def test_room_defaults(self):
        "Defaults are being passed correctly"
        self.assertEquals(self.room.name, "Room")
        self.assertEquals(self.room.objects,
                          [self.dresser, self.bed, self.lamp])
        self.assertEquals(self.room.description, "A room.")
        self.assertEquals(self.room.exits, {'south': self.southern_room})

    def test_room_look(self):
        "room.look() returns room.description"
        self.assertEquals(self.room.look(), self.room.description)

    def test_move_room(self):
        """Calling move should return the room object that is in that direction.  
        If the direction does not exist, an error should be thrown."""
        # existing direction
        self.assertEquals(self.room.move('south', []), self.southern_room)
        # direction that does not exist
        self.assertEquals(self.room.move('west', []),
                          "You cannot go that way.")

    def test_move_when_standing(self):
        "User should not be able to move locations when standing on something"
        # when chair is in user's inventory
        inv = [self.chair]
        self.chair.has_user = True
        self.assertEquals(self.room.move('south', inv),
                          "You must climb down first.")
        # when chair is in the room
        self.room.objects.append(self.chair)
        self.assertEquals(self.room.move('south', []),
                          "You must climb down first.")
        # but should succeed when the user gets down
        self.chair.has_user = False
        self.assertEquals(self.room.move('south', []), self.southern_room)

    def test_equality(self):
        "Two rooms should be considered equal if they have the same name, description, objects, and exits"
        name, desc, exits = self.room.name, self.room.description, self.room.exits
        objs = [Dresser(), Lamp(), Bed()]
        other_room = Room(name, objs, desc, exits)
        # equal
        self.assertTrue(self.room == other_room)
        other_room.objects.pop()
        # not equal
        self.assertFalse(self.room == other_room)
Example #10
0
 def setUp(self):
     self.dresser = Dresser()
     self.bed = Bed()
     self.lamp = Lamp()
     self.room = Room(name = "Room", objects = [self.dresser, self.bed, self.lamp], description = "A room.", exits={})
Example #11
0
from scaffolding import Room, Object, \
                        Bed, Dresser, UnreachableLamp, Chair

global inventory
inventory = []
global location

bed = Bed()
lamp = UnreachableLamp()
dresser = Dresser()
chair = Chair()

Bedroom = Room(name='Bedroom', objects=[bed, lamp, dresser], description='A homey room with blue wallpaper \
and old-fashioned scenes hanging from brass frames.  There is a large four-poster against one wall \
and a small dresser in the corner.', exits={})
Closet = Room(name='Closet', objects=[chair], description='Significantly colder than the bedroom, \
the closet has a slanted roof that only makes it feel more cramped', exits={})

Bedroom.exits['west'] = Closet
Closet.exits['east'] = Bedroom
lamp._room = Bedroom

location = Bedroom

# GLOBAL METHODS
def get(obj):
    return obj.get(location, inventory)

def drop(obj):
    return obj.drop(location, inventory)