def __init__(self, pos_x, pos_y): pygame.sprite.Sprite.__init__(self) self.pos_x = pos_x self.pos_y = pos_y self.walk_frames = actor.DirAction('NPC', '', '', 1, 4, True) self.dir = 0 self.step_count = 0 self.width = 32 self.height = 48 self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height) self.crashed = False self.get = False self.dialog = Dialog(400, 190, '你好勇士 我是这里的仙人 被魔界人追杀到这里 功力全失 我依稀还记得腾云驾雾 你是否要学习呢 (按Y键学习腾云驾雾)', True) self.dialog_get = Dialog(400, 70, '你已经学习了腾云驾雾')
def start(token, backend, db, dialog, filename): bot = init_backend(token, backend) path = db['path'] del db['path'] db_path = init_db(path, **db) db = Db(db_path) dialog = Dialog(db, dialog) print('Start') while True: messages = bot.get_unread_messages() if messages["count"] >= 1: id, message_id, body, url = bot.get_message_ids_image(messages) print('Запрос:', id, body) try: if url and url[-3:] == 'jpg': urllib.request.urlretrieve(url, filename) db.save_image(id, body, filename) bot.send_message(id, dialog.ok) continue if body.lower() in dialog.common_answer: bot.send_message(id, dialog.common_answer[body.lower()]) continue for key in dialog.action: if key in body.lower(): part = body.lower().split(':')[1].strip() if '&' in body.lower(): splitted = part.split('&') part_1, part_2 = splitted[0].strip( ), splitted[1].strip() db.hset(id, part_1, part_2) bot.send_message(id, dialog.ok) break data = db.hget(id, part) if data and len(data) > 15000: with open(filename, 'wb') as file: file.write(data) bot.upload_image(id, filename) break elif data: bot.send_message(id, data) else: bot.send_message(id, dialog.text_does_not_exist) break else: bot.send_message(id, dialog.don_t_understand) except Exception as e: print(str(e)) bot.send_message(id, dialog.error) time.sleep(1)
def __init__(self, pos_x, pos_y, width, height): pygame.sprite.Sprite.__init__(self) self.pos_x = pos_x self.pos_y = pos_y self.width = width self.height = height self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height) self.crashed = False self.dialog = Dialog(400, 130, '你并不会腾云驾雾技能 不能再往前面走了 按任意键继续')
def __init__(self, pos_x, pos_y): pygame.sprite.Sprite.__init__(self) self.pos_x = pos_x self.pos_y = pos_y self.walk_frames = actor.DirAction('sword2', '', '', 1, 1, True) self.width = 64 self.height = 64 self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height) self.crashed = False self.get = False self.dialog = Dialog(400, 130, '成功获得了武器蜂刺 攻击力提升10 按任意键继续')
def __init__(self, pos_x, pos_y): pygame.sprite.Sprite.__init__(self) self.pos_x = pos_x self.pos_y = pos_y self.walk_frames = actor.DirAction('sword3', '', '', 1, 1, True) self.width = 64 self.height = 64 self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height) self.crashed = False self.get = False self.dialog = Dialog(400, 190, '恭喜你成功集齐三把神器 合成获得神器三相之力 获得了神一般的力量 按任意键继续')
def __init__(self, pos_x, pos_y): pygame.sprite.Sprite.__init__(self) self.pos_x = pos_x self.pos_y = pos_y self.walk_frames = actor.DirAction('monster2', '', '', 1, 4, True) self.width = 312 * 2 self.height = 310 * 2 self.hp = 1000 self.max_hp = 1000 self.attack = 150 self.rect = pygame.Rect(self.pos_x, self.pos_y, self.width, self.height) self.crashed = False self.get = False self.dialog = Dialog(240, 180, '遇到怪物 开始战斗 按任意键继续')