예제 #1
0
def main(win):
    pth = os.path.join("res", "stockfish", "path.txt")
    configured = os.path.exists(pth)
    if configured:
        with open(pth, "r") as f:
            configured = teststockfish(f.read().strip())

    clock = pygame.time.Clock()
    while True:
        clock.tick(24)
        showScreen(win, configured)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return 0

            elif event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos

                if 460 < x < 500 and 0 < y < 50:
                    return 1

                if 120 < x < 370 and 320 < y < 350:
                    if configured:
                        os.remove(pth)
                        configured = False

                    ret = guideMain(win)
                    if ret in [0, 1]:
                        return ret

        pygame.display.update()
예제 #2
0
def install(win, pth):
    pygame.draw.rect(win, (0, 0, 0), (100, 200, 300, 100))
    pygame.draw.rect(win, (255, 255, 255), (100, 200, 300, 100), 4)
    win.blit(STOCKFISH.LOADING, (100, 200))
    pygame.display.update()

    pygame.draw.rect(win, (0, 0, 0), (100, 200, 300, 100))
    pygame.draw.rect(win, (255, 255, 255), (100, 200, 300, 100), 4)

    pygame.draw.rect(win, (255, 255, 255), (220, 270, 65, 20), 2)
    win.blit(STOCKFISH.BACK, (220, 270))

    active = teststockfish(pth)
    if active:
        with open(os.path.join("res", "stockfish", "path.txt"), "w") as f:
            f.write(pth)
        for cnt, i in enumerate(STOCKFISH.SUCCESS):
            win.blit(i, (120, 206 + cnt * 17))
    else:
        for cnt, i in enumerate(STOCKFISH.NOSUCCESS):
            win.blit(i, (130, 206 + cnt * 17))

    pygame.display.update()
    clock = pygame.time.Clock()
    while True:
        clock.tick(24)
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                if 220 < event.pos[0] < 285 and 270 < event.pos[1] < 290:
                    if active:
                        return 1
                    else:
                        return 2
예제 #3
0
def main(win):
    sel = sel2 = 0
    lvl = 1
    clock = pygame.time.Clock()
    while True:
        clock.tick(24)
        showScreen(win, sel, sel2, lvl)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return 0
            elif event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if 460 < x < 500 and 0 < y < 50:
                    return 1

                if 160 < y < 210 and 200 < x < 350:
                    sel = (x // 50) - 4

                if 430 < y < 480 and 150 < x < 300:
                    sel2 = (x // 50) - 3

                if 380 < y < 410:
                    for i in range(9):
                        if 110 + i * 35 < x < 135 + i * 35:
                            lvl = i + 1

                if 170 < x < 310 and 220 < y < 250:
                    if sel == 2:
                        return True, random.randint(0, 1)
                    else:
                        return True, sel

                if 320 < x < 460 and 440 < y < 470:
                    pth = os.path.join("res", "stockfish", "path.txt")
                    if os.path.exists(pth):
                        with open(pth, "r") as f:
                            if teststockfish(f.read().strip()):
                                if sel2 == 2:
                                    return False, random.randint(0, 1), lvl
                                else:
                                    return False, sel2, lvl

                    if prompt(win):
                        return stockfish.main(win)
        pygame.display.update()