def Check(m=3): Apos, Aval = Moving.autoFing(getView(), 'error.png') if (Aval): pos, val = Moving.autoFing(getView(), 'bos.png') mode, text = Combat(m) Check(m + 1) else: time.sleep(2) Bpos, Bval = Moving.autoFing(getMap(), 'ambush.png') if (Bval): Cpos, Cval = Moving.autoFing(getMap(), 'escape.png') if Cval: tap_scale(Cpos) print('幹你地雷!') print('重新Attack') Attack() else: time.sleep(2) Dpos, Dval = Moving.attack(getView(), 'attack.png') if Dval: tap_scale(Dpos) print('幹中標@_@') else: print('重新Attack') Attack()
def start_stage(sleep_time=4): im = screenshot.pull_screenshot2CV() pos, val = Moving.go(im) adb.tap_scale(pos) time.sleep(1) im = screenshot.pull_screenshot2CV() pos, val = Moving.go(im) adb.tap_scale(pos) time.sleep(sleep_time)
def is_harborfull(): im = screenshot.pull_screenshot2CV() if Moving.is_harborfull(im): pos, val = Moving.sortout(im) adb.tap_scale(pos) im = screenshot.pull_screenshot2CV() pos, val = Moving.onekey_retire(im) adb.tap_scale(pos) time.sleep()
def Combat(mode=0): time.sleep(4) # getView() if mode == 0: pos, val = Moving.autoFing(getView(), 'bos.png') if val: Combat(1) else: Combat(2) if mode == 1: pos, val = Moving.autoFing(getMap(), 'bos.png') if val: print('發現Boss') tap_scale(pos) return (mode, 'Boss') else: Combat(2) else: if mode == 2: pos, val = Moving.autoFing(getMap(), 'A.png') if val: print('發現A') tap_scale(pos) return (mode, '小艇') else: Combat(3) else: if mode == 3: pos, val = Moving.autoFing(getMap(), 'C.png') if val: print('發現C') tap_scale(pos) return (mode, '航母') else: Combat(4) else: if mode == 4: pos, val = Moving.autoFing(getMap(), 'B.png') if val: print('發現B') tap_scale(pos) return (mode, '戰艦') else: Combat(5) else: print('壞掉了 目前找不到或是退出') return (5, '???')
def main2(): screenshot.check_screenshot() # im = screenshot.pull_screenshot2CV() # page = cv2.imread('resource/image/echoofredC.jpg') # if Moving.find_page(im,page): # print('page not find') # exit(1) while True: find_stage('SP3') start_stage() # choose_ship('heianjie') while True: im = screenshot.pull_screenshot2CV() pos = Moving.find_enemy(im) posx = pos adb.tap_scale(pos) time.sleep(4.5) while True: im = screenshot.pull_screenshot2CV() pos, val = Moving.attack(im) if val < 0.05: print('出击!') adb.tap_scale(pos) break else: pos, val = Moving.ambush(im) if val < 0.1: print('遭遇伏击!规避') TapButton.escape(im, adb) else: print('遭遇空袭!继续进行') # 继续 adb.tap_scale(posx) time.sleep(2.5) val = 1 while val > 0.05: print("判断是否战斗结束,若未能进入战斗状态,请手动进入战斗") time.sleep(1) im = screenshot.pull_screenshot2CV() pos, val = Moving.finished(im) adb.tap_scale(pos) time.sleep(0.5) adb.tap_scale((500, 300)) time.sleep(1.5) im = screenshot.pull_screenshot2CV() TapButton.confirm(im, adb) time.sleep(4.5)
def endGame(): print('===================') Apos, Aval = Moving.autoFing(getView(), 'endC.png') if Aval: print(Apos) tap_scale(Apos) Bpos, Bval = Moving.autoFing(getView(), 'endC.png') if Bval: print(Bpos) tap_scale(Bpos) Cpos, Cval = Moving.autoFing(getView(), 'accept.png') if Cval: print(Bpos) tap_scale(Cpos) print('退出關卡')
def adjust_page(): pos = 900, -400 adb.swipe_scale(pos) im = screenshot.pull_screenshot2CV() pos = Moving.find_mapbottomedge(im) pos = -int(pos[0]), 443 - int(pos[1]) adb.swipe_scale(pos)
def test_moving(times): action, search = 0, 0 for i in range(times): map = Map.Map(50) me = Moving.MovingExplorer(origin_map=map) a, s = me.search() action += a search += s # print("Average Search Times: " + str(res / times)) return action, search
def Sheep(): time.sleep(10) Ppos, Pval = Moving.autoFing(getView(), 'pause.png') print(Ppos, '遊戲中..') if (Pval): print('等待遊戲結束') time.sleep(30) Sheep() else: print('結束中...') endGame()
def Attack(): Combat(0) Check() time.sleep(2) ATpos, ATval = Moving.autoFing(getView(), 'attack.png') if (ATval): tap_scale(ATpos) print('載入戰鬥...') Sheep() else: print('被卡住? 再次點擊') Combat(1) time.sleep(1)
def main(): screenshot.check_screenshot() im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) x, y = adb.get_size() if x < y: x, y = y, x scale = (x / 960, y / 443) pos, val = Moving.find_stage(im, '3-4') tap_scale(pos, scale) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.go(im) tap_scale(pos, scale) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.go(im) tap_scale(pos, scale) time.sleep(4) while True: im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos = Moving.find_enemy(im) posx = pos tap_scale(pos, scale) time.sleep(4.5) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.attack(im) if val < 0.05: print('出击!') tap_scale(pos, scale) else: pos, val = Moving.ambush(im) if val < 0.1: print('遭遇伏击!规避') pos, val = Moving.escape(im) tap_scale(pos, scale) else: print('遭遇空袭!继续进行') tap_scale(posx, scale) # 继续 tap_scale(posx, scale) time.sleep(2.5) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.attack(im) # 出击 tap_scale(pos, scale) val = 1 while val > 0.06: print("判断是否战斗结束,若未能进入战斗状态,请手动进入战斗") time.sleep(1) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.finished(im) tap_scale(pos, scale) time.sleep(0.5) tap_scale((500, 300), scale) time.sleep(1.5) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.accept(im) tap_scale(pos, scale) time.sleep(4.5) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.find_stage(im, '3-4') if val < 0.06: tap_scale(pos, scale) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.go(im) tap_scale(pos, scale) im = screenshot.pull_screenshot() im = screenshot.Image2OpenCV(im) pos, val = Moving.go(im) tap_scale(pos, scale) time.sleep(4)
def test_findStage(self): screenshot.check_screenshot() im = screenshot.pull_screenshot2CV() Moving.find_stage(im, 'C1')
def find_stage(stage, sleep_time=1): im = screenshot.pull_screenshot2CV() pos, val = Moving.find_stage(im, stage) adb.tap_scale(pos) time.sleep(sleep_time)
def choose_ship(ship_name): im = screenshot.pull_screenshot2CV() pos, val = Moving.find_ship(im, ship_name) adb.tap_scale(pos) adjust_page()
def test_template_matching(self): im1 = image_reader('testemeny') im2 = image_reader('boss') # template_matching(im1,im2) Moving.find_enemy(im1)