Beispiel #1
0
def showScreen(win, boardS, flags, pos, show_moves, load=False, player=None):
    side = boardS[0]
    board = boardS[1]

    if player is None:
        flip = load and boardS[0]
    else:
        flip = load and player
    drawBoard(win)

    if player is not None:
        win.blit(Chess.DRAW_TEXT, Chess.DRAW_POS)
        win.blit(Chess.RESIGN_TEXT, Chess.RESIGN_POS)

        x, y = pygame.mouse.get_pos()

        if checkPos(Chess.DRAW_POS, x, y):
            win.blit(Chess.DRAW_TEXTB, Chess.DRAW_POS[:2])

        if checkPos(Chess.RESIGN_POS, x, y):
            win.blit(Chess.RESIGN_TEXTB, Chess.RESIGN_POS[:2])

        win.blit(Chess.MOVE[int(side == player)], (10, 460))

    else:
        win.blit(Chess.SAVE_TEXT, Chess.SAVE_POS[:2])
        x, y = pygame.mouse.get_pos()

        if checkPos(Chess.SAVE_POS, x, y):
            win.blit(Chess.SAVE_TEXTB, Chess.SAVE_POS[:2])

    if endGame(boardS, flags):
        #pygame.draw.rect(win, PROMPT, Chess.CM_PROMPT_POS)
        #pygame.draw.rect(win, PROMPTB, Chess.CM_PROMPTB_POS, 3)
        if inCheck(boardS):
            if player is None:
                win.blit(Chess.GAME_ENDED[0], Chess.GAME_ENDED_POS)

            if player is not None:
                win.blit(Chess.END_GAME0[int(side == player)],
                         Chess.END_GAME_POS)

        else:
            if player is None:
                win.blit(Chess.GAME_ENDED[1], Chess.GAME_ENDED_POS)

    elif inCheck(boardS):
        win.blit(Chess.CHECK, Chess.CHECK_POS)

    drawPieces(win, board, flip)

    if show_moves:
        showMoves(win, boardS, pos, flags, flip)

    pygame.display.update()
Beispiel #2
0
def main(win):
    win.fill(LoadGame.BACKGROUND)
    pygame.draw.rect(win, PROMPT, LoadGame.PROMPT_POS)
    pygame.draw.rect(win, PROMPTB, LoadGame.PROMPTB_POS, 3)

    win.blit(LoadGame.LOAD_GAME, LoadGame.LOAD_POS)
    win.blit(LoadGame.SINGLE_YES, LoadGame.SINGLE_YES_POS)
    win.blit(LoadGame.MULTI_YES, LoadGame.MULTI_YES_POS)

    br = 0
    screen = -1

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return 0, ""

            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if checkPos(LoadGame.SINGLE_YES_POS, x, y):
                    showScreen(win)
                    br = 1
                    screen = 0
                elif checkPos(LoadGame.MULTI_YES_POS, x, y):
                    showScreen2(win)
                    br = 1
                    screen = 1
        if br == 1:
            break
        pygame.display.update()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos

                if screen == 0:
                    for idx in range(len(LoadGame.SINGLE_BTNS_POS)):
                        if checkPos(LoadGame.SINGLE_BTNS_POS[idx], x, y):
                            #print(LoadGame.SINGLE_MOVES2[idx])
                            return screen, LoadGame.SINGLE_MOVES2[idx]
                elif screen == 1:
                    for idx in range(len(LoadGame.MULTI_BTNS_POS)):
                        if checkPos(LoadGame.MULTI_BTNS_POS[idx], x, y):
                            #print(LoadGame.MULTI_MOVES2[idx])
                            return screen, LoadGame.MULTI_MOVES2[idx]

        pygame.display.update()
Beispiel #3
0
def quitPrompt(win):
    pygame.draw.rect(win, PROMPT, Chess.QS_PROMPT_POS)
    pygame.draw.rect(win, PROMPTB, Chess.QS_PROMPTB_POS, 3)

    win.blit(Chess.MSG_Q, Chess.QS_MSG_POS)
    win.blit(Chess.QS_YES, Chess.YES_SQ_POS)
    win.blit(Chess.QS_NO, Chess.NO_SQ_POS)

    clock = pygame.time.Clock()
    while True:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if checkPos(Chess.NO_SQ_POS, x, y):
                    return False
                if checkPos(Chess.YES_SQ_POS, x, y):
                    return True

        pygame.display.update()
Beispiel #4
0
def prompt(win, flag):
    pygame.draw.rect(win, PROMPT, Settings.PROMPT_POS)
    pygame.draw.rect(win, PROMPTB, Settings.PROMPTB_POS, 3)

    if (flag == 0):
        win.blit(Settings.SHOW_MOVES1, Settings.SHOW_MOVES1_POS)
    else:
        win.blit(Settings.FLIP_BOARD1, Settings.FLIP_BOARD1_POS)

  #  win.blit(Settings.YES1, Settings.YES1_POS)
  #  win.blit(Settings.NO1, Settings.NO1_POS)

    clock = pygame.time.Clock()
    while True:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if checkPos(Settings.NO1_POS, x, y):
                    return False
                if checkPos(Settings.YES1_POS, x, y):
                    return True

        pygame.display.update()
Beispiel #5
0
def promoteChoice(win, side):
    win.blit(Chess.PROMOTION, (65, 15))
    if side == 0:
        for idx in range(4):
            win.blit(
                pygame.image.load('resources/images/' + Chess.W_PROM[idx]),
                Chess.WB_POS[idx])

        pygame.display.update()
        while True:
            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN:
                    x, y = event.pos
                    if checkPos(Chess.QUEEN_POS, x, y):
                        return 'q'
                    elif checkPos(Chess.BISHOP_POS, x, y):
                        return 'b'
                    elif checkPos(Chess.ROOK_POS, x, y):
                        return 'r'
                    elif checkPos(Chess.KNIGHT_POS, x, y):
                        return 'n'

    else:
        for idx in range(4):
            win.blit(
                pygame.image.load('resources/images/' + Chess.B_PROM[idx]),
                Chess.WB_POS[idx])

        pygame.display.update()
        while True:
            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN:
                    x, y = event.pos
                    if checkPos(Chess.QUEEN_POS, x, y):
                        return 'q'
                    elif checkPos(Chess.BISHOP_POS, x, y):
                        return 'b'
                    elif checkPos(Chess.ROOK_POS, x, y):
                        return 'r'
                    elif checkPos(Chess.KNIGHT_POS, x, y):
                        return 'n'
Beispiel #6
0
def  main(win):
    win.fill(LoadGame.BACKGROUND)
    pygame.draw.rect(win, PROMPT, Settings.PROMPT_POS1)
    pygame.draw.rect(win, PROMPTB, Settings.PROMPTB_POS1, 3)

    win.blit(Settings.SHOW_MOVES, Settings.SHOW_MOVES_POS)
    #win.blit(Settings.YES, Settings.SHOW_YES_POS)
    #win.blit(Settings.NO, Settings.SHOW_NO_POS)

    pygame.draw.rect(win, PROMPT, Settings.PROMPT_POS2)
    pygame.draw.rect(win, PROMPTB, Settings.PROMPTB_POS2, 3)

    win.blit(Settings.FLIP_BOARD, Settings.FLIP_BOARD_POS)
    #win.blit(Settings.YES, Settings.FLIP_YES_POS)
    #win.blit(Settings.NO, Settings.FLIP_NO_POS)

    sett = [True, True]

    while True:

        x, y = pygame.mouse.get_pos()
        if (checkPos(Settings.SHOW_YES_POS, x, y)):
            win.blit(Settings.YESB, Settings.SHOW_YES_POS)
        else:
            win.blit(Settings.YES, Settings.SHOW_YES_POS)

        if (checkPos(Settings.SHOW_NO_POS, x, y)):
            win.blit(Settings.NOB, Settings.SHOW_NO_POS)
        else:
            win.blit(Settings.NO, Settings.SHOW_NO_POS)

        if (checkPos(Settings.FLIP_YES_POS, x, y)):
            win.blit(Settings.YESB, Settings.FLIP_YES_POS)
        else:
            win.blit(Settings.YES, Settings.FLIP_YES_POS)

        if (checkPos(Settings.FLIP_NO_POS, x, y)):
            win.blit(Settings.NOB, Settings.FLIP_NO_POS)
        else:
            win.blit(Settings.NO, Settings.FLIP_NO_POS)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                    return sett

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

                if (checkPos(Settings.SHOW_YES_POS, x, y)):
                    sett[0] = True

                if (checkPos(Settings.SHOW_NO_POS, x, y)):
                    sett[0] = False

                if (checkPos(Settings.FLIP_YES_POS, x, y)):
                    sett[1] = True

                if (checkPos(Settings.FLIP_NO_POS, x, y)):
                    sett[1] = False

        pygame.display.update()
Beispiel #7
0
def main():
    window.blit(BACKGROUND, (0, 0))
    window.blit(Main.TITLE_TEXT, Main.TITLE_POS)
    for x, y in zip(Main.btns_txt, Main.btns_pos):
        window.blit(x, y[:2])


running = True
while running:
    pygame.display.flip()
    clock.tick(10)

    main()
    x, y = pygame.mouse.get_pos()
    for index, z in enumerate(Main.btns_pos):
        if checkPos(z, x, y):
            window.blit(Main.btns_txtb[index], z[:2])

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()

            # SINGLEPLAYER
            if checkPos(Main.SINGLEPLAYER_POS, x, y):
                games.singleplayer(window, -1, LOAD[0])

            # MULTIPLAYER
            elif checkPos(Main.MULTIPLAYER_POS, x, y):
                games.multiplayer(window, LOAD)
Beispiel #8
0
def main(win, player, show_moves, moves=""):
    if moves == "":
        win.fill(LoadGame.BACKGROUND)

        pygame.draw.rect(win, PROMPT, Chess.QS_PROMPT_POS)
        pygame.draw.rect(win, PROMPTB, Chess.QS_PROMPTB_POS, 3)

        win.blit(Chess.SG_GAME, Chess.SG_POS)
        win.blit(Chess.WHITE_C, Chess.WHITE_POS)
        win.blit(Chess.BLACK_C, Chess.BLACK_POS)

        player = -1
        br = 0
        clock = pygame.time.Clock()
        while True:
            clock.tick(30)
            pygame.display.update()
            '''
            x, y = pygame.mouse.get_pos()
            if checkPos(Chess.BLACK_POS, x, y):
                win.blit(Chess.BLACKB_C, Chess.BLACK_POS)
            elif checkPos(Chess.WHITE_POS, x, y):
                win.blit(Chess.WHITEB_C, Chess.WHITE_POS)
            '''

            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN:
                    x, y = event.pos
                    if checkPos(Chess.BLACK_POS, x, y):
                        player = 1
                        br = 1
                    if checkPos(Chess.WHITE_POS, x, y):
                        player = 0
                        br = 1
            if br == 1:
                break

    side, board, flags = convertMoves(moves)
    clock = pygame.time.Clock()
    fromPos = toPos = [0, 0]

    while True:
        boardS = [side, board]
        clock.tick(30)
        endG = endGame(boardS, flags)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                if (quitPrompt(win) == True):
                    pygame.time.delay(150)
                    return
                else:
                    pygame.time.delay(150)
                    pass

            elif event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if 50 < x < 450 and 50 < y < 450:
                    x, y = x // 50, y // 50
                    if False and boardS[0]:
                        x, y = 9 - x, 9 - y

                    fromPos = toPos
                    toPos = [x, y]
                elif boardS[0] == player or endG:
                    toPos = [0, 0]
                    if checkPos(Chess.SAVE_POS, x, y):
                        if (savePrompt(win) == False):
                            pygame.time.delay(150)
                        else:
                            pygame.time.delay(150)
                            saveGame(moves, "Singleplayer game", 0)

        showScreen(win, boardS, flags, toPos, show_moves)
        if side != player:
            if not endG:
                fromPos, toPos = minimax(boardS, flags)
                animate(win, boardS, fromPos, toPos, False and player)
                if pieceType(
                        boardS,
                        fromPos) == 'p' and toPos[1] == 8 or toPos[1] == 1:
                    moves += " " + encode(fromPos, toPos, 'q')
                else:
                    moves += " " + encode(fromPos, toPos)
                side, board, flags = makeMove(boardS, fromPos, toPos, flags)
                toPos = [0, 0]

        elif isValidMove(boardS, flags, fromPos, toPos):
            promote = promotePawn(win, boardS, fromPos, toPos, True)
            animate(win, boardS, fromPos, toPos, bool(False and player))
            side, board, flags = makeMove(boardS, fromPos, toPos, flags,
                                          promote)
            moves += " " + encode(fromPos, toPos, promote)