def loop_current_page_game(self): i = self.try_find_time game_list = [] while i: game_list = self.game_page.get_game_list() if len(game_list) != 0: break i = i - 1 time.sleep(1) if len(game_list) == 0: raise Exception("子游戏列表为空") for game in game_list: game_name = game.get_attribute('name') self.log_info("====准备进入子游戏:%s====" % game_name) if game_name in self.excluded_game:#['game20', 'game2002']: continue r_v = PHPInterface.set_match_config(game=int(game_name.replace("game", "")), basechiptype=0, playmode=0, roomlevel=12+self.level, baseconfig="BASE_CHIPS=>100,HIGH_LIMIT=>-1,HIGH_LIMIT_EXIT=>-1,SERVICE_FEE=>10,ADDROBOTFLAG=>1,ROBOT_MAX_NUMBER=>2", extraconfig="") self.log_info("设置场次接口返回值:%s" % str(r_v)) if self.enter_game_room(game_name, find_in_elements=False, level=self.level): self.ready() # 游戏开始后 while 1: if not self.try_find_element("换桌"): break time.sleep(1) while 1: try: chat = self.try_find_element("牌局开始时聊天按钮", page_object=self.game_page) if chat: chat.click() else: chat = self.try_find_element("聊天", page_object=self.game_page) if chat: chat.click() self.game_page.get_element("聊天记录", timesleep=1).click() self.log_info("等到我出牌") while 1: my_turn = self.try_find_element("timer_light_1", find_in_elements=False) if my_turn: self.log_info("到我出牌") break else: my_turn = self.try_find_element("prompt", find_in_elements=False) if my_turn: self.log_info("到我出牌") break time.sleep(1) self.game_page.screenshot('my_turn_chat_%s.png' % game_name) count = self._check_button_count() if count != 3: raise Exception("当前界面不对") break except: pass self.luadriver.keyevent(4) self.wait_for_gameover() self.back_to_hall()
def loop_current_page_game(self): i = self.try_find_time game_list = [] while i: game_list = self.game_page.get_game_list() if len(game_list) != 0: break i = i - 1 time.sleep(1) if len(game_list) == 0: raise Exception("子游戏列表为空") for game in game_list: game_name = game.get_attribute('name') self.log_info("====准备进入子游戏:%s====" % game_name) if game_name in self.excluded_game: #['game20', 'game2002']: continue r_v = PHPInterface.set_match_config( game=int(game_name.replace("game", "")), basechiptype=0, playmode=0, roomlevel=12 + self.level, baseconfig= "BASE_CHIPS=>100,HIGH_LIMIT=>-1,HIGH_LIMIT_EXIT=>-1,SERVICE_FEE=>10,ADDROBOTFLAG=>1,ROBOT_MAX_NUMBER=>2", extraconfig="") self.log_info("设置场次接口返回值:%s" % str(r_v)) if self.enter_game_room(game_name, find_in_elements=False, level=self.level): self.ready() # 游戏开始后 while 1: if not self.try_find_element("换桌"): break time.sleep(1) self.log_info("等待游戏结束") end_time = time.time() + self.child_game_timeout * 60 jdz_has_clicked = False ddz_qf_clicked = False end_tag_showed = False close_btn_showed = False while 1: # 超时10分钟, 睡眠间隔2s ddz_gameover = self.try_find_element( "ddz_gameover", find_in_elements=False) # ready_btn = self.game_page.wait_element("牌局结束标志", timeout=60 * self.child_game_timeout, frequency=2) if ddz_gameover: end_tag_showed = True self.log_info("ddz_gameover: 牌局已结束") close_btn = self.try_find_element( "关闭按钮", page_object=self.hall_page) if close_btn: close_btn_showed = True self.log_info("关闭按钮: 牌局已结束") if end_tag_showed or close_btn_showed: if not close_btn_showed: counter = self.try_find_element( "btnView", find_in_elements=False) if counter: counter.click() self.game_page.screenshot("counter_%s.png" % game_name) break share_btn = self.try_find_element("share_btn", find_in_elements=False) if share_btn: self.log_info("share_btn: 牌局已结束") self.try_find_element("close_btn", find_in_elements=False, try_time=3).click() close_btn_showed = True break if not jdz_has_clicked: jdz = self.try_find_element("callLordBtn", find_in_elements=False) if jdz: jdz.click() # 新斗地主,叫地主按钮会在一瞬间消失,此时点击准备按钮会跑在(0,0)位置 if self.element_exists("退出", page_object=self.game_page, timesleep=1): self.log_info("点击叫地主, 存在退出按钮") self.luadriver.keyevent(4) jdz_has_clicked = True self.log_info("点击叫地主") if not ddz_qf_clicked: qf = self.try_find_element("叫抢场1分", page_object=self.game_page) if qf: qf.click() self.log_info("点击抢分1分") ddz_qf_clicked = True if self.element_exists("退出", page_object=self.game_page, timesleep=1): self.log_info("点击叫抢场1分, 存在退出按钮") self.luadriver.keyevent(4) if time.time() > end_time: self.log_info("游戏超时") raise Exception("玩游戏超时") self.back_to_hall()