Ejemplo n.º 1
0
def test_room():
    print('Creating Room:')
    width = input_value('Input width:')
    length = input_value('Input length:')
    height = input_value('Input height:')
    doors = input_value('Input doors count:')
    windows = input_value('Input windows count:')

    my_room = Room(width, length, height, doors, windows)
    print(my_room)
    print('Square: ' + str(my_room.wall_square()))
    print('Only walls square: ' + str(my_room.wall_only_square()))
    del my_room
Ejemplo n.º 2
0
 def create_room(self, mem_id, name, floor, room_type):
     """Create room object and return"""
     new_room = Room.create_room(
         mem_id, name, floor, room_type, self.capacity,
         self.no_of_occupants
     )
     return new_room
Ejemplo n.º 3
0
 def get_allocations_as_dict(people, rooms=None):
     """Get allocation table from pkl file and return as dictionary"""
     if rooms is None:
         rooms = []
     allocations = Person.get_allocations(people)
     allocations = Room.add_empty_rooms_to_allocation(rooms, allocations)
     return allocations
Ejemplo n.º 4
0
    def create_room(self, name: str, description: str = '') -> Room:
        if self.name_exists(name):
            raise RoomAlreadyExistsError(payload={'name': name})

        room = Room(name, description)
        self.rooms[room.id] = room
        self._broadcast_update()
        return room
Ejemplo n.º 5
0
    def test_wall_only_square(self):
        print('-----')
        print('Test wall only square:')
        width = 5
        length = 5
        height = 5
        doors = 1
        windows = 1

        room_square = 2 * (width + length) * height

        my_room = Room(width, length, height, doors, windows)

        self.assertEqual(my_room.wall_only_square(),
                         room_square,
                         msg='Wrong wall square!')
        print('-----')
Ejemplo n.º 6
0
 def reallocate_person(person_id, room_name, people, rooms):
     """
     Transfer person with the supplied person identifier to a different room
     Also performs fresh allocations if person has not been allocated a room
     of this type.
     Args:
         person_identifier -- an identifier that recognizes person
         room_name -- name of new room
         people -- list of person objects
         rooms -- list of room objects
     Returns
         aperson -- person object with updates to the rooms attribute
         errors -- a list of non destructive errors that occurred
     """
     person = Person()
     room = Room()
     new_room = room.get_room(room_name, rooms)
     person = person.get_person(person_id, people)
     if not new_room:
         raise ValueError("No room was found in memory with that name. "
                          "You may want to create a new room with that\n"
                          "name or view all rooms in memory by requesting "
                          "allocations.")
     if not person:
         raise ValueError("No person was found in memory for person "
                          "identifier supplied.")
     if person.type == "staff" and new_room.type == "living space":
         raise RuntimeError("You cannot allocate staff to 'living space'.")
     person = room.remove_room_of_same_type(rooms, new_room, person)
     person.add_rooms_to_person([new_room])
     room.increment_number_of_occupants(rooms, new_room.mem_id)
     return person
Ejemplo n.º 7
0
def save_room():
    print('Creating Room:')
    width = input_value('Input width:')
    length = input_value('Input length:')
    height = input_value('Input height:')
    doors = input_value('Input doors count:')
    windows = input_value('Input windows count:')

    my_room = Room(width, length, height, doors, windows)
    print('-----')
    print(my_room)
    print('-----')

    dump(my_room)
Ejemplo n.º 8
0
    def __init__(self):
        default_room = Room('Default Room',
                            'You join here by default',
                            is_permament=True)
        default_room.id = '_default'

        test_room = Room('Testing',
                         'A permament room used for testing',
                         is_permament=True)
        test_room.id = '_test'

        self.socketio: SocketIO = None
        self.default_room = default_room
        self.rooms: Dict[str, Room] = {
            '_default': default_room,
            '_test': test_room
        }
Ejemplo n.º 9
0
    def test_save(self):
        print('-----')
        print('Save-load test:')
        type_code = random.choice(
            [Room.CODE, Kitchen.CODE, Bathroom.CODE, LivingRoom.CODE])
        width = random.randint(5, 10)
        length = random.randint(5, 10)
        height = random.randint(5, 10)
        doors = random.randint(5, 10)
        windows = random.randint(5, 10)

        kitchen_width = random.randint(5, 10)
        kitchen_height = random.randint(5, 10)

        if type_code is Kitchen.CODE:
            my_room = Kitchen(width, length, height, doors, windows,
                              kitchen_width, kitchen_height)
        elif type_code is Bathroom.CODE:
            my_room = Bathroom(width, length, height)
        elif type_code is LivingRoom.CODE:
            my_room = LivingRoom(width, length, height, doors, windows)
        else:
            my_room = Room(width, length, height, doors, windows)

        dump(my_room, "test.room")
        my_room_loaded = load_room("test.room")

        self.assertEqual(type(my_room).__name__,
                         type(my_room_loaded).__name__,
                         msg='Type is incorrect!')
        self.assertEqual(my_room.width,
                         my_room_loaded.width,
                         msg='Width is incorrect!')
        self.assertEqual(my_room.height,
                         my_room_loaded.height,
                         msg='Height is incorrect!')
Ejemplo n.º 10
0
    def add_person(mem_id, first_name, last_name, employee_type,
                   wants_accommodation, rooms):
        """Adds new person to room
        Args:
            mem_id -- an id used to identify to objects held in memory
            first_name -- person's first name
            last_name -- person's last name
            employee_type -- is the person a fellow or staff
            wants_accommodation -- should be "Y" or "N" indicating if fellow
                                   wants accommodation
            rooms -- a list of all rooms in Amity
        Result:
            new_person -- a new Fellow or Staff object
            errors -- a list of non destructive errors that occurred
        """
        person = Person()
        room = Room()
        allocated_rooms = []
        errors = []
        new_person = person.create_person(
            mem_id, first_name, last_name, employee_type)

        if room.check_room_type_has_vacancy(rooms, "office"):
            allocated_rooms.append(room.get_random_room(rooms, "office"))
        else:
            errors.append("There is no vacant office currently in "
                          "Amity!!!")

        if new_person.type == "fellow" and wants_accommodation == "Y":
            if room.check_room_type_has_vacancy(rooms, "living space"):
                allocated_rooms.append(room.get_random_room(rooms,
                                       "living space"))
            else:
                errors.append("There is no vacant living space currently in "
                              "Amity!!!")

        new_person = new_person.add_rooms_to_person(allocated_rooms)
        return new_person, errors
Ejemplo n.º 11
0
nest = 'nest'
forest = 'forest'
outside = 'outside'
foyer = 'foyer'
overlook = 'overlook'
narrow = 'narrow'
treasure = 'treasure'

from rooms.room import Room
from data.items import quantum_microscope, intellicorium_microscope, splitting_microscope, sword

rooms = {
    nest:
    Room(nest, 'Dragon\'s Nest', 'A stone-faced dragon lies dormant.'),
    forest:
    Room(forest, 'Waywards Forest', 'Hoots and toots lie here.'),
    outside:
    Room(outside, 'Outside Cave Entrance',
         'North of you, the cave mount beckons.'),
    foyer:
    Room(
        foyer, 'Foyer', '''Dim light filters in from the south. Dusty
passages run north and east.'''),
    overlook:
    Room(
        overlook, 'Grand Overlook',
        '''A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.''',
        [quantum_microscope, intellicorium_microscope, splitting_microscope]),
    narrow:
Ejemplo n.º 12
0
    def create_rooms(self):
        rooms = self.rooms
        items = self.items

        # Create rooms:
        room1 = Room(
            "A small room with a blue door on the north wall and a table in one of the corners. On the table there is a blue key and an unlit torch.",
            1)
        room2 = Room("A dark room. You need a light or you can't see anything",
                     2)
        room3 = Room(
            "A big room with 3 doors. A green one west, red one east and a yellow one north. There is a bookshelf with a weird book near the green door.",
            3)
        room4 = Room(
            "A small room with no other doors. There is a safe on top of a table in the center of the room. The safe has 3 buttons, each with a number: 11, 12 and 13. \nWritten in a piece of paper near the safe is the sequence \"0,1,1,2,3,5,8...\"",
            4)
        room5 = Room(
            "A normal size room with nothing except a door in the north wall. On the side of the door there is a panel with 4 buttons having a single letter each : R, Y, G, B.",
            5)
        room6 = Room(
            "An enourmos room filled with treasure and gold. You can see a sign near the door with the words \"Congratulations, you beat the game\" written on it.",
            6)

        room2.dark = True

        # Add room position on the map:
        room1.room_map = '###############\n######[ ]######\n######[ ]######\n###[ ][ ][ ]###\n######[X]######\n###############\nX = You'
        room2.room_map = '###############\n######[ ]######\n######[ ]######\n###[X][ ][ ]###\n######[ ]######\n###############\nX = You'
        room3.room_map = '###############\n######[ ]######\n######[ ]######\n###[ ][X][ ]###\n######[ ]######\n###############\nX = You'
        room4.room_map = '###############\n######[ ]######\n######[ ]######\n###[ ][ ][X]###\n######[ ]######\n###############\nX = You'
        room5.room_map = '###############\n######[ ]######\n######[X]######\n###[ ][ ][ ]###\n######[ ]######\n###############\nX = You'
        room6.room_map = '###############\n######[X]######\n######[ ]######\n###[ ][ ][ ]###\n######[ ]######\n###############\nX = You'

        # Connect rooms:
        room1.north_room = room3

        room2.east_room = room3

        room3.south_room = room1
        room3.west_room = room2
        room3.east_room = room4
        room3.north_room = room5

        room4.west_room = room3

        room5.south_room = room3
        room5.north_room = room6

        room6.south_room = room5

        # Create doors:
        door_1to3 = Door(description='A blue door')
        door_1to3.id = 0
        door_1to3.color = 'blue'
        items['blue door'] = door_1to3

        door_2to3 = Door(description='A green door')
        door_2to3.id = 1
        door_2to3.color = 'green'
        items['green door'] = door_2to3

        door_3to4 = Door(description='A red door')
        door_3to4.id = 2
        door_3to4.color = 'red'
        items['red door'] = door_3to4

        door_3to5 = Door(description='A yellow door')
        door_3to5.id = 3
        door_3to5.color = 'yellow'
        items['yellow door'] = door_3to5

        door_5to6 = Door(description='A white door')
        door_5to6.id = 4
        door_5to6.color = 'white'
        items['white door'] = door_5to6

        # Add doors to rooms:
        room1.north_door = door_1to3
        room2.east_door = door_2to3
        room3.west_door = door_2to3
        room3.east_door = door_3to4
        room3.north_door = door_3to5
        room3.south_door = door_1to3
        room4.west_door = door_3to4
        room5.north_door = door_5to6
        room6.south_door = door_5to6

        # Add rooms to room list:
        rooms.append(room1)
        rooms.append(room2)
        rooms.append(room3)
        rooms.append(room4)
        rooms.append(room5)
        rooms.append(room6)
Ejemplo n.º 13
0
 def _join_room(self, requester: User, room: Room):
   broadcast_room_joined(requester, room.id)
   join_room(room.id)
   emit('current_room_changed', room.to_dict())
Ejemplo n.º 14
0
 def is_room_type_valid(room_type):
     """Returns True if room type is valid and False, otherwise"""
     return Room.is_room_type_valid(room_type)
Ejemplo n.º 15
0
    length = input_value('Input length:')
    height = input_value('Input height:')

    my_bathroom = Bathroom(width, length, height)
    print(my_bathroom)
    print('Adding a door...')
    my_bathroom.doors_count += 1
    print(my_bathroom)
    print('Square: ' + str(my_bathroom.wall_square()))
    print('Only walls square: ' + str(my_bathroom.wall_only_square()))
    del my_bathroom


print('Constant value demo: ')
print("Creating Room:")
my_room = Room(width=8, height=5)
print(my_room)
print('Adding a door...')
my_room.doors_count += 1
print(my_room)
del my_room

print("Creating Kitchen:")
my_kitchen = Kitchen(kitchen_width=5, kitchen_height=2)
print('Wall\'s square with kitchen: '.format(
    my_kitchen.wall_square(without_kitchen=False)))
print('Wall\'s square without kitchen: '.format(my_kitchen.wall_square()))
del my_kitchen

print("Creating Bathroom:")
my_bathroom = Bathroom(width=5, height=2)