Пример #1
0
 def create(self):
     DatabaseManager.get_instance().insert_row(
         'Player', {
             'telegram_chat_id': self.telegram_chat_id,
             'username': self.username,
             'coins': self.coins
         })
Пример #2
0
 def find_all_quest_rooms(cls):
     db_manager = DatabaseManager.get_instance()
     table = db_manager.get_table(
         'QuestRoom',
         ['id', 'name', 'count_of_players', 'complexity', 'description'])
     for row in table:
         yield cls(*row)
Пример #3
0
 def get_by_id(cls, id_):
     db_manager = DatabaseManager.get_instance()
     row = db_manager.get_row('Room',
                              id_,
                              columns=['name', 'quest_room_id'])
     quest_room = QuestRoom.get_by_id(row[1])
     return cls(id_, row[0], quest_room)
Пример #4
0
 def start_location(self):
     try:
         db_manager = DatabaseManager.get_instance()
         loc_id = db_manager.get_one_value_of_one_table(
             'QuestRoom', 'start_location_id', self.id)
         return Location.get_by_id(loc_id)
     except MySQLdb._exceptions.OperationalError:
         return None
Пример #5
0
 def get_by_id(cls, id_):
     db_manager = DatabaseManager.get_instance()
     row = db_manager.get_row('QuestRoom',
                              id_,
                              columns=[
                                  'id', 'name', 'count_of_players',
                                  'complexity', 'description'
                              ])
     return cls(*row)
Пример #6
0
 def identify_player(cls, telegram_chat_id):
     player_data = DatabaseManager.get_instance().get_row(
         'Player',
         telegram_chat_id,
         primary_str='telegram_chat_id',
         columns=['telegram_chat_id', 'username', 'coins'])
     if player_data is None:
         return None
     else:
         print(player_data)
         return cls(*player_data)
Пример #7
0
    def get_adjacent_locations(self):
        db_manager = DatabaseManager.get_instance()

        query = f"""
                        SELECT Location.id, Location.name, Location.room_id FROM
                        (
                        SELECT * FROM AccessLine
                        WHERE AccessLine.from_id = {self._id}
                        ) as temp
                        JOIN Location ON temp.to_id = Location.id
                """
        result = db_manager.execute(query, True)
        for row in result:
            if row[2] == self._room.id:
                room = self._room
            else:
                r = db_manager.get_row('Room', row[2])
                room = Room(r[0], r[1], self._room.quest_room)
            yield Location(row[0], row[1], room)
Пример #8
0
 def get_by_id(cls, id_):
     db_manager = DatabaseManager.get_instance()
     row = db_manager.get_row('Location', id_, columns=['name', 'room_id'])
     room = Room.get_by_id(row[1])
     return cls(id_, row[0], room)
Пример #9
0
 def get_locations_by_room(cls, room):
     db_manager = DatabaseManager.get_instance()
     table = db_manager.get_table('Location', ['id', 'name'],
                                  f'room_id = {room.id}')
     for row in table:
         yield Location(row[0], row[1], room)
Пример #10
0
 def get_rooms_by_quest_room(cls, quest_room):
     db_manager = DatabaseManager.get_instance()
     table = db_manager.get_table('Room', ['id', 'name'],
                                  f'quest_room_id = {quest_room.id}')
     for row in table:
         yield Room(row[0], row[1], quest_room)
Пример #11
0
 def get_location_id(self):
     loc_id = DatabaseManager.get_instance().get_one_value_of_one_table(
         'Player', 'location_id', self.telegram_chat_id, 'telegram_chat_id')
     return loc_id
Пример #12
0
 def set_location(self, location):
     DatabaseManager.get_instance().update_one_value_of_one_table(
         'Player', 'location_id', location.id, self.telegram_chat_id,
         'telegram_chat_id')
Пример #13
0
 def save(self):
     DatabaseManager.get_instance().update_row(self.get_dict(), 'Player',
                                               self.telegram_chat_id,
                                               'telegram_chat_id')