예제 #1
0
def test_invalid_level_rooms(capsys, room1, hallway):
    room2 = Room(start, dimensions, tiles, doors)
    level = Level([room1, room2], [hallway])
    valid_level = check_level(level)
    capture = capsys.readouterr()
    assert capture.out == 'Invalid Level: Duplicate rooms\n'
    assert valid_level == False
예제 #2
0
def test_invalid_level_dimensions(capsys, level1):
    invalid_dimensions = Room(Coord(6, 1), Coord(6, 6), tiles, doors)
    level1.rooms.append(invalid_dimensions)
    valid_level = check_level(level1)
    capture = capsys.readouterr()
    assert capture.out == 'Invalid Level: Overlapping Room(s) or Hallway(s)\n'
    assert valid_level == False
예제 #3
0
def parse_room_obj(room_input):
    try:
        room_json = json.loads(room_input)
    except TypeError:
        room_json = room_input
    origin = None
    bounds = None
    layout = None
    point = None
    try:
        # [Room, Point] format 
        if room_json[0][TYPE] != ROOM:
            print('Invalid Args: Type is not room')
            return None
        input_json = room_json[0]
        point = room_json[1]
    except (KeyError, IndexError):
        input_json = room_json
    origin = input_json[ORIGIN]
    bounds = input_json[BOUNDS]
    layout = input_json[LAYOUT]

    origin_coord = to_coord(origin)
    dimensions = Coord(bounds[ROWS], bounds[COLS])
    tiles = []
    doors = []
    for ii in range(0, bounds[ROWS]):
        for jj in range(0, bounds[COLS]):
            # ii = x jj = y
            if layout[ii][jj] != 0:
                tiles.append(Coord(origin[0] + ii, origin[1] + jj))
            if layout[ii][jj] == 2:
                doors.append(Coord(origin[0] + ii, origin[1] + jj))
    return {COORD: to_coord(point) if point else None, ROOM: Room(origin_coord, dimensions, tiles, doors)}
예제 #4
0
def room3():
    tiles1 = [
        Coord(7, 1),
        Coord(7, 2),
        Coord(7, 3),
        Coord(7, 18),
        Coord(6, 4),
        Coord(6, 1),
        Coord(6, 3),
        Coord(7, 5),
        Coord(8, 4),
        Coord(8, 2),
        Coord(8, 3),
        Coord(8, 4),
        Coord(8, 5),
        Coord(9, 2),
        Coord(9, 3),
        Coord(9, 4)
    ]
    start1 = Coord(5, 0)
    dimensions1 = Coord(5, 5)
    doors1 = [Coord(7, 5)]
    items1 = [Coord(6, 1), Coord(7, 3)]
    room3 = Room(start1, dimensions1, tiles1, doors1, items1)
    return room3
예제 #5
0
파일: room_test.py 프로젝트: nzukie-b/snarl
def room1():
    tiles = [
        Coord(7, 6),
        Coord(7, 8),
        Coord(7, 9),
        Coord(7, 10),
        Coord(6, 6),
        Coord(6, 8),
        Coord(8, 9),
        Coord(8, 6),
        Coord(8, 7),
        Coord(8, 8),
        Coord(8, 9),
        Coord(8, 10),
        Coord(9, 6),
        Coord(9, 7),
        Coord(9, 8),
        Coord(6, 10)
    ]
    start = Coord(5, 5)
    dimensions = Coord(5, 5)
    doors = [Coord(8, 10), Coord(7, 10), Coord(6, 10)]
    items = [Coord(6, 6), Coord(7, 8)]
    room1 = Room(start, dimensions, tiles, doors, items)
    return room1
예제 #6
0
파일: gamestate.py 프로젝트: nzukie-b/snarl
def remove_doors_and_items_from_rooms(first):
    '''Remove doors and items from walkable tiles. Used to determine initial placement of entities'''
    first_rm = copy.deepcopy(first)
    first_rm_removed = []
    for tile in first_rm.tiles:
        if tile not in first.doors and tile not in first.items:
            first_rm_removed.append(tile)
    return Room(first_rm.origin, first_rm.dimensions, first_rm_removed,
                first_rm.doors, first_rm.items)
예제 #7
0
 def get_available_rooms(cls):
     url = f"{constants.SERVER_DOMAIN}/rooms"
     headers = {'x-access-token': cls.player_token}
     response = requests.get(url, headers=headers)
     rooms_as_dict = response.json()
     rooms_as_obj = [
         Room.dict_to_obj(room_as_dict)
         for room_as_dict in rooms_as_dict.values()
     ]
     return rooms_as_obj
예제 #8
0
    def test_b(self):
        room = Room(100, 50)
        tile = Tile(60, 20)
        border = 0
        init = {}

        installation = Installation(room, tile, border, init)
        plan = installation.process()
        installation.print()
        self.sanity_checks(init, plan, room, border)
예제 #9
0
def room2():
    #Room 2 example
    tiles1 = [Coord(7, 15), Coord(7, 17), Coord(7, 18), Coord(6, 17), Coord(8, 17), Coord(8, 15), 
                Coord(6, 15), Coord(7, 15), Coord(7, 15), Coord(9, 17), Coord(9, 16), Coord(9, 15), Coord (9, 15), Coord(6, 16)]
    start1 = Coord(5, 15)
    dimensions1 = Coord(5, 5)
    doors1 = [Coord(7, 15)]
    items1 = [Coord(8, 17), Coord(7, 17)]
    room2 = Room(start1, dimensions1, tiles1, doors1, items1)
    return room2
예제 #10
0
    def add_room(self, pos=None):

        if pos is not None:
            new_room = self.add_room()
            new_room._set_pos(pos)
        else:
            new_room = Room('New Room')
            # self._camera_table_model.begin_append()
            self.add_feature(new_room)
            # self._camera_table_model.end_append()

        return new_room
예제 #11
0
    def test_a(self):
        room = Room(3330, 2700)
        tile = Tile(1286, 194)
        border = 8
        init = {
            0: 1286,
            12: 1286
        }

        installation = Installation(room, tile, border, init)
        plan = installation.process()
        installation.print()
        self.sanity_checks(init, plan, room, border)
예제 #12
0
 def display_room_details_by_room_name(cls):
     room_name = input("Please insert the name of the room: ")
     print("")
     url = f"{constants.SERVER_DOMAIN}/rooms/{room_name}"
     headers = {'x-access-token': cls.player_token}
     response = requests.get(url, headers=headers)
     room_as_dict = response.json()
     if not room_as_dict:
         print(f"{RoomsAPIErrors.ROOM_NAME_DOESNT_EXIST.value}\n")
     else:
         room_as_obj = Room.dict_to_obj(room_as_dict)
         print(room_as_obj)
     cls.display_main_menu()
예제 #13
0
    def process(self):
        actual_room = Room(self.room.l1 - 2 * self.border,
                           self.room.l2 - 2 * self.border)

        rows = math.ceil(actual_room.l2 / self.tile.width)
        rest = 0
        result = []
        for r in range(rows):
            row, rest = self.create_row(actual_room, rest, self.init_tiles, r,
                                        (r + 1) == rows)
            result.append(row)

        return Plan(actual_room, result)
예제 #14
0
def host_room(current_player):
    data = request.json
    room_name = data['room_name']
    if DBMethods.check_if_room_with_same_name_already_exists(room_name):
        return jsonify({'result': RoomsAPIErrors.ROOM_NAME_OCCUPIED.value})
    if DBMethods.check_if_player_already_in_a_room(current_player.username):
        return jsonify(
            {'result': RoomsAPIErrors.PLAYER_ALREADY_IN_A_ROOM.value})
    room_id = str(uuid.uuid4())
    room = Room(room_id, room_name, RoomState.WAITING.value, [current_player],
                current_player)
    DBMethods.add_room_to_db(room)
    DBMethods.update_player_linked_room_in_db(current_player.username, room_id)
    return jsonify({'result': 'success'})
예제 #15
0
def main():
    room = Room(3330, 2700)
    tile = Tile(1286, 194)
    border = 8
    init = {
        5: 1286,
        10: 1286
    }

    installation = Installation(room, tile, border, init)

    plan = installation.process()
    installation.print()
    Printer.print(plan)
예제 #16
0
def get_room(room_id):
    if type(room_id) == Room:
        raise TypeError('Using Room object instead of room_id.')

    room = rooms_collection.find_one({'_id': ObjectId(room_id)})
    bucket_number = get_latest_bucket_number(room_id)

    try:
        emoji = room['emoji']
    except KeyError as e:
        emoji = ''
    except TypeError as e:
        emoji = ''

    room_object = Room(room['name'],
                       str(room_id),
                       room['is_dm'],
                       bucket_number,
                       str(room['created_by']),
                       emoji=emoji)
    room_object.set_messages(get_messages(
        str(room_id), bucket_number))  # this line may be causing issues
    return room_object
예제 #17
0
class TestRoom(unittest.TestCase):
    """Test cases for Room class"""
    room = Room('Orion')

    def test_new_room_class(self):
        self.assertEqual(type(self.room), Room)

    def test_new_room_name(self):
        self.assertEqual(self.room.name, 'Orion')

    def test_new_room_members(self):
        self.assertEqual(self.room.members, {})

    def test_new_room_occupants(self):
        self.assertEqual(self.room.no_of_occupants, 0)

    def test_create_room_raises_error(self):
        self.assertRaises(Exception, Room, [1, 3, 4])
예제 #18
0
 def create_room_object_from_dict(cls, room_as_dict):
     room_id = room_as_dict["id"]
     room_name = room_as_dict["name"]
     room_state = room_as_dict["state"]
     host_username = room_as_dict["host_username"]
     players_as_dict = cls.get_players_in_room_from_db(room_id)
     players_as_objects = []
     for player_as_dict in players_as_dict:
         player_id = player_as_dict['id']
         player_username = player_as_dict["username"]
         player_password = player_as_dict["password"]
         player_as_object = Player(player_id, player_username,
                                   player_password)
         players_as_objects.append(player_as_object)
     host_of_room = cls.get_host_of_room_by_host_username(
         host_username, players_as_objects)
     room_as_obj = Room(room_id, room_name, room_state, players_as_objects,
                        host_of_room)
     return room_as_obj
예제 #19
0
파일: room_test.py 프로젝트: nzukie-b/snarl
def invalid_tiles():
    '''Initializes example Room with invalid Tiles'''
    invalid_tiles = [
        Coord(11, 10),
        Coord(7, 6),
        Coord(7, 8),
        Coord(7, 9),
        Coord(7, 10),
        Coord(6, 6),
        Coord(6, 8),
        Coord(8, 9),
        Coord(8, 6),
        Coord(8, 7),
        Coord(8, 8),
        Coord(8, 9),
        Coord(8, 10),
        Coord(9, 6),
        Coord(9, 7),
        Coord(9, 8),
        Coord(6, 10)
    ]
    room = Room(start, dimensions, invalid_tiles, doors, items)
    return room
예제 #20
0
파일: room_test.py 프로젝트: nzukie-b/snarl
def invalid_doors():
    '''Initializes example Room with invalid Doors'''
    invalid_doors = [Coord(8, 10), Coord(7, 10), Coord(5, 5), Coord(6, 10)]
    room = Room(start, dimensions, tiles, invalid_doors, items)
    return room
예제 #21
0
 def add(cls, room_id, creator_user_id):
     room = Room(room_id, creator_user_id)
     db_session.add(room)
     db_session.commit()
     return room
예제 #22
0
def invalid_hallway():
    '''Initializes an invalid Hallway'''
    hall_start = Coord(0, 0)
    hall = Hallway([hall_start, Coord(5, 5)], [Room(start, dimensions, [Coord(5, 5)], [Coord(3, 3)])])
    return hall
예제 #23
0
def horizontal_hallway():
    '''Initializes a Hallway with a horizontal orientation'''
    #hall_start = Coord(0, 0)
    hall_start = Coord(4, 3)
    hall = Hallway([hall_start, Coord(4, 5)], [Room(start, dimensions, [Coord(5, 3)], [Coord(5, 3)])])
    return hall
예제 #24
0
def room1():
    '''Initializes example Room'''
    room = Room(start, dimensions, tiles, doors, items)
    return room
예제 #25
0
 def on_create_room(self, message):
     uid = message.nUserID
     newRoom = Room(uid, GameHandler.waiters[uid])
     self.room_cache[newRoom.m_id] = newRoom
예제 #26
0
from model.room import Room
from model.reservation import Reservation


# schema
Base.metadata.create_all(engine)

# session
session = Session()

# users
jeca = User("Jelica", "Stanojevic", "jeca", "jeca123")
mika = User("Milica", "Miljkovic", "mika", "mika123")

# rooms
room1 = Room(1, 50.0, 1, False)
room2 = Room(2, 80.0, 1, False)
room3 = Room(3, 100.0, 1, False)
room11 = Room(1, 60.0, 2, True)
room22 = Room(2, 90.0, 2, True)
room33 = Room(3, 110.0, 2, True)
room111 = Room(1, 60.0, 3, True)
room222 = Room(2, 90.0, 3, True)
room333 = Room(3, 110.0, 3, True)

# reservations
res1 = Reservation("Maja", "Nikolic", 111111111, date(
    2018, 8, 20), date(2018, 8, 25), room1)
res2 = Reservation("Uros", "Velickovic", 222222222,
                   date(2018, 9, 20), date(2018, 9, 25), room22)
res3 = Reservation("Milunka", "Djokic", 333333333, date(