#coding=utf-8

from mylib import *

test()
def yu_ling(window_size):
    global is_start
    topx, topy = window_size[0], window_size[1]
    state = []

    while is_start:
        # print 'start'
        # text.insert('end', 'start')
        time.sleep(0.5)
        img_ready = ImageGrab.grab((topx + get_posx(750, window_size), topy + get_posy(465, window_size),
                                    topx + get_posx(840, window_size), topy + get_posy(500, window_size)))
        if hamming(get_hash(img_ready), ready_hash, 10):
            state.append(0)
            move_click(topx + get_posx(740, window_size), topy + get_posy(380, window_size))
            text.insert('end', strftime('%H:%M:%S', localtime()) + ' 点击准备\n')
            text.see('end')  # 自动显示底部
            time.sleep(15)
            continue

        img_success = ImageGrab.grab((topx + get_posx(400, window_size), topy + get_posy(320, window_size),
                                      topx + get_posx(470, window_size), topy + get_posy(400, window_size)))
        if hamming(get_hash(img_success), success_hash):
            time.sleep(2)
            state.append(1)
            text.insert('end', strftime('%H:%M:%S', localtime()) + ' 成功%d次\n' % state.count(1))
            text.see('end')  # 自动显示底部
            move_click(topx + get_posx(730, window_size), topy + get_posy(380, window_size))
            continue

        img_fail = ImageGrab.grab((topx + get_posx(560, window_size), topy + get_posy(340, window_size),
                                   topx + get_posx(610, window_size), topy + get_posy(390, window_size)))
        if hamming(get_hash(img_fail), fail_hash):
            time.sleep(2)
            state.append(2)
            text.insert('end', strftime('%H:%M:%S', localtime()) + ' 失败%d次\n' % state.count(2))
            text.see('end')  # 自动显示底部
            move_click(topx + get_posx(720, window_size), topy + get_posy(380, window_size))
            continue

        img_attack = ImageGrab.grab((topx + get_posx(615, window_size), topy + get_posy(350, window_size),
                                     topx + get_posx(675, window_size), topy + get_posy(375, window_size)))
        if hamming(get_hash(img_attack), yu_attack_hash):
            move_click(topx + get_posx(670, window_size), topy + get_posy(365, window_size))
            text.insert('end', strftime('%H:%M:%S', localtime()) + ' 点击进攻\n')
            text.see('end')  # 自动显示底部
            state.append(3)
            if state[-6:] == [3]*6:
                text.insert('end', strftime('%H:%M:%S', localtime()) + ' 痴汉券可能不够了\n')
                text.see('end')  # 自动显示底部
                click()
                break
            continue