def find_room_occupied_by_player(self, player_id): """ Retrieve the room occupied by a player. Args: player_id the ID of the player. Returns: The Room that the player is in. Raises: PlayerNotInRoom if the data is inconsistent and no room exists that the player is in. This generally indicates a bug. """ self.cursor.execute( """ select rooms.id, rooms.name, rooms.description, rooms.final_room from rooms, players where players.id=:player_id and players.currently_in_room=rooms.id """, {"player_id": player_id}, ) result = self.cursor.fetchone() if result is None: raise PlayerNotInRoom return Room.from_row(result)
def add_room(self, room): """ Add a room to the configuration. Args: room the room to add. Returns: A Room object with id set to the database value. """ self.cursor.execute( "insert into rooms values (null, :name, :description, :final_room)", {"name": room.get_name(), "description": room.get_description(), "final_room": room.is_final_room()}, ) self.connection.commit() return Room.from_row((self.cursor.lastrowid, room.get_name(), room.get_description(), room.is_final_room()))
def find_room_by_name(self, room_name): """ TODO Replace, there could be multiple rooms with the same name, in multiple instances of the game. """ self.cursor.execute("select * from rooms where name=:name", {"name": room_name}) row = self.cursor.fetchone() return Room.from_row(row)