Example #1
0
 def click(self, x, y):
     logger.debug('点击-%s,%s' % (x, y))
     long_position = MAKELONG(x, y)
     PostMessage(self.hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON,
                 long_position)
     PostMessage(self.hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,
                 long_position)
Example #2
0
 def check_auto_battle(self):
     auto_sense = self.find_imgs([u"resource/img/auto.png", u"resource/img/manual.png"])
     if auto_sense[0] == 0:
         logger.debug("已经自动战斗")
     elif auto_sense[0] == 1:
         logger.debug("开启自动战斗")
         self.wait_img_click(u"resource/img/manual.png", 1)
Example #3
0
 def click_img(self, template_img_path, center=False):
     """
     点击图片
     :param center:
     :param template_img_path:要点击的图片
     :return:
     """
     pos = self.screenshot_find(template_img_path)
     if pos is not None:
         self.click(pos, center)
         return pos
     else:
         logger.debug("点击图片失败,未找到图片" + template_img_path)
Example #4
0
 def wait_imgs(self, sense_paths, max_time=30):
     """
     等待多个图片其中一个存在,返回检测到的数组下标
     :return:
     """
     logger.debug("等待游戏场景")
     start_time = time()
     while time() - start_time <= max_time:
         sleep(0.1)
         pos = self.find_imgs(sense_paths)
         if pos is not None:
             return pos
     return None
Example #5
0
 def wait_img(self, img_path, max_time=30):
     """
     等待游戏图像
         :param max_time:
         :param self:
         :param img_path:
         :return: 成功返回图片位置[left_top,right_bottom],失败返回None
     """
     logger.debug("等待游戏图像")
     start_time = time()
     while time() - start_time <= max_time:
         sleep(0.1)
         pos = self.screenshot_find(img_path)
         if pos is not None:
             return pos
     logger.debug("等待图像失败" + img_path)
     return None
Example #6
0
 def battle(self, teammates_number, captain=False):
     """
     战斗模块
     :return:
     """
     isWin = False
     logger.info("等待战斗开始")
     if self.wait_img(u"resource/img/battleLeftTop.png", 120) is not None:
         logger.info("进入战斗场景")
         """
         进入了战斗画面
         """
         self.click_ready()
     else:
         raise Exception("进入战斗场景失败")
     logger.info("等待战斗结束")
     count = 0
     while True:
         sleep(0.2)
         pos = self.wait_imgs([u"resource/img/win.png", u"resource/img/fail.png", u"resource/img/guihuo.png"], 10)
         if pos is not None:
             count = 0
             if pos[0] == 0:
                 logger.info("战斗胜利")
                 isWin = True
                 self.win_deal(teammates_number, captain)
                 break
             elif pos[0] == 1:
                 logger.info("战斗失败")
                 self.fail_deal(teammates_number, captain)
                 break
             elif pos[0] == 2:
                 logger.debug("战斗中...")
         else:
             count = count + 1
             if count > 5:
                 raise Exception("未知战斗场景")
     return isWin
Example #7
0
 def mouse_up(self, x, y):
     logger.debug('鼠标弹起-%s,%s' % (x, y))
     long_position = MAKELONG(x, y)
     PostMessage(self.hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON,
                 long_position)