예제 #1
0
def animate(win, side, board, fro, to, load, player=None):
    sound.play_drag(load)
    if player is None:
        FLIP = side and load["flip"]
    else:
        FLIP = player and load["flip"]

    piece = CHESS.PIECES[side][getType(side, board, fro)]
    x1, y1 = fro[0] * 50, fro[1] * 50
    x2, y2 = to[0] * 50, to[1] * 50
    if FLIP:
        x1, y1 = 450 - x1, 450 - y1
        x2, y2 = 450 - x2, 450 - y2

    stepx = (x2 - x1) / 50
    stepy = (y2 - y1) / 50

    col = (180, 100, 30) if (fro[0] + fro[1]) % 2 else (220, 240, 240)

    clk = pygame.time.Clock()
    for i in range(51):
        clk.tick_busy_loop(100)
        drawBoard(win)
        drawPieces(win, board, FLIP)

        pygame.draw.rect(win, col, (x1, y1, 50, 50))
        win.blit(piece, (x1 + (i * stepx), y1 + (i * stepy)))
        pygame.display.update()
    sound.play_move(load)
예제 #2
0
def showScreen(win, side, board, flags, pos, load, player=None, online=False):
    multi = False
    if player is None:
        multi = True
        player = side

    flip = load["flip"] and player

    drawBoard(win)
    win.blit(BACK, (460, 0))

    if not multi:
        win.blit(CHESS.TURN[int(side == player)], (10, 460))

    if not online:
        if load["allow_undo"]:
            win.blit(CHESS.UNDO, (10, 12))
        win.blit(CHESS.SAVE, (350, 462))

    if isEnd(side, board, flags):
        if isChecked(side, board):
            win.blit(CHESS.CHECKMATE, (100, 12))
            win.blit(CHESS.LOST, (320, 12))
            win.blit(CHESS.PIECES[side]["k"], (270, 0))
        else:
            win.blit(CHESS.STALEMATE, (160, 12))
    else:
        if online:
            win.blit(CHESS.DRAW, (10, 12))
            win.blit(CHESS.RESIGN, (400, 462))

        if isChecked(side, board):
            win.blit(CHESS.CHECK, (200, 12))

        if isOccupied(side, board, pos) and side == player:
            x = (9 - pos[0]) * 50 if flip else pos[0] * 50
            y = (9 - pos[1]) * 50 if flip else pos[1] * 50
            pygame.draw.rect(win, (255, 255, 0), (x, y, 50, 50))

    drawPieces(win, board, flip)
    if load["show_moves"] and side == player:
        showAvailMoves(win, side, board, pos, flags, flip)

    if not multi:
        pygame.display.update()
예제 #3
0
def animate(win, side, board, fro, to, flip):
    piece = CHESS.PIECES[side][getType(side, board, fro)]
    x1, y1 = fro[0] * 50, fro[1] * 50
    x2, y2 = to[0] * 50, to[1] * 50
    if flip:
        x1, y1 = 450 - x1, 450 - y1
        x2, y2 = 450 - x2, 450 - y2

    stepx = (x2 - x1) / 50
    stepy = (y2 - y1) / 50

    col = (180, 100, 30) if (fro[0] + fro[1]) % 2 else (220, 240, 240)

    for i in range(50):
        pygame.time.delay(6)
        drawBoard(win)
        drawPieces(win, board, flip)

        pygame.draw.rect(win, col, (x1, y1, 50, 50))
        win.blit(piece, (x1 + (i * stepx), y1 + (i * stepy)))
        pygame.display.update()
    drawBoard(win)
예제 #4
0
def showScreen(win, side, board, flags, pos, LOAD, player=None, online=False):
    multi = False
    if player is None:
        multi = True
        player = side

    flip = LOAD[1] and player

    drawBoard(win)

    if not multi:
        win.blit(CHESS.TURN[int(side == player)], (10, 460))

    if not online:
        if LOAD[4]:
            win.blit(CHESS.UNDO, (10, 10))
        win.blit(CHESS.SAVE, (350, 460))

    if isEnd(side, board, flags):
        if isChecked(side, board):
            win.blit(CHESS.CHECKMATE, (140, 12))
            win.blit(CHESS.LOST, (370, 12))
            win.blit(CHESS.PIECES[side]["k"], (320, 0))
        else:
            win.blit(CHESS.STALEMATE, (150, 12))
    else:
        if isChecked(side, board):
            win.blit(CHESS.CHECK, (180, 12))

        if isOccupied(side, board, pos) and side == player:
            x = (9 - pos[0]) * 50 if flip else pos[0] * 50
            y = (9 - pos[1]) * 50 if flip else pos[1] * 50
            pygame.draw.rect(win, (255, 255, 0), (x, y, 50, 50))

    drawPieces(win, board, flip)
    if LOAD[3] and side == player:
        showAvailMoves(win, side, board, pos, flags, flip)
    pygame.display.update()