示例#1
0
def page(screen):

    # ----- "Start" button -----
    start_button_size = size.Size(600, 500, width=100, height=50)
    start_button = button.Button(screen, start_button_size, "play", border=13)

    # ----- Logo -----
    logo_size = size.Size(600, 250, 550, 550)
    logo = image.Image(screen, 'assets\pages\logo.png', logo_size)

    # ----- Main loop -----
    while True:
        screen.fill(colors.white)

        # ---- Events ----
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            start_button.onHover(event)
            if start_button.onTap(event):
                second_page.page(screen)

        start_button.draw()  # draw "start" button.
        logo.draw()  # draw the app logo image.

        # ---- Updates ----
        pygame.display.update()
        pygame.time.Clock().tick(60)
示例#2
0
def page(screen, users={1: 'player1', 2:'player2'}):

    # ----- TextField -----
    player1_name_text = text.Text(
        screen, 'Player 1 name:', 460, 250, 18, fg_color=colors.gray_dark)
    player1_name_texteditingcontroller = texteditingcontroller.TextEditingController()
    player1_name_size = size.Size(710, 250, 250, 50)
    player1_name_textfield = textfield.TextField(screen, player1_name_size,
                                                 player1_name_texteditingcontroller,
                                                 default_text=users[1]
                                                 )
    
    # ----- "next" button -----
    next_button_size = size.Size(600, 500, 100, 50)
    next_button = button.Button(screen, next_button_size, 'next', border=13)
    
    # ----- back button -----
    back_button_size = size.Size(50, 50, width=70, height=70)
    back_button = image.Image(screen, 'assets/icons/back.png', back_button_size)

    # ----- Main loop -----
    while True:
        screen.fill(colors.white)

        # ---- Events ----
        for event in pygame.event.get():
            if event.type == pygame.QUIT: # EXIT
                pygame.quit()
                sys.exit()

            player1_name_textfield.typing(event)

            if next_button.onTap(event): # NEXT
                player1_name = player1_name_texteditingcontroller.text
                users[1] = player1_name
                third_page.page(screen, users) # NAVIGATOR

            if back_button.onTap(event): # BACK
                first_page.page(screen)

            next_button.onHover(event) # NEXT(hover)

        # ---- TextField ----
        player1_name_text.draw()
        player1_name_textfield.draw()
        
        # ---- buttons ----
        next_button.draw()
        back_button.draw()

        # ---- Updates ----
        pygame.display.update()
        pygame.time.Clock().tick(60)
示例#3
0
 def init_menu_button(self):
     menu_button_size = size.Size(self.inside_table_size.right - 20,
                                  self.inside_table_size.top - 20,
                                  width=30,
                                  height=23)
     menu_button = image.Image(self.screen, 'assets/icons/menu.png',
                               menu_button_size)
     return menu_button
示例#4
0
def init_check(screen):
    check_size = size.Size(685, 300, 100, 45)
    check_text = text.Text(screen,
                           'CHECK!',
                           685,
                           300,
                           18,
                           fg_color=colors.brown_light)

    return {'size': check_size, 'text': check_text}
示例#5
0
 def init_undo_button(self):
     undo_button_size = size.Size(self.inside_table_size.left + 35,
                                  self.inside_table_size.top - 20,
                                  width=60,
                                  height=23)
     undo_button = button.Button(self.screen,
                                 undo_button_size,
                                 'UNDO',
                                 background_color=self.colors['dark'])
     return undo_button
示例#6
0
def page(screen):
    loading_image_size = size.Size(600, 300, 1210, 605)
    loading_image = image.Image(screen, 'assets/pages/loading.png',
                                loading_image_size)

    loading_image.draw()
    pygame.display.update()

    time.sleep(1)
    return
示例#7
0
def page(screen, users):
    x, y = screen.get_size()

    winner_name = users[2].upper()
    winner_text = text.Text(screen,
                            f'{winner_name} WINS!',
                            x // 2,
                            250,
                            80,
                            fg_color=colors.gray_dark)

    quit_button_size = size.Size(480, 500, 130, 50)
    quit_button = button.Button(screen, quit_button_size, 'QUIT')

    rematch_button_size = size.Size(720, 500, 130, 50)
    rematch_button = button.Button(screen, rematch_button_size, 'REMATCH')

    while True:
        screen.fill(colors.white)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

            if quit_button.onTap(event):
                pygame.quit()
                sys.exit()
            if rematch_button.onTap(event):
                second_page.page(screen, users)

            quit_button.onHover(event)
            rematch_button.onHover(event)

        winner_text.draw()
        quit_button.draw()
        rematch_button.draw()

        pygame.display.update()
示例#8
0
 def dict_to_list(self, dict):
     self.piece_list.clear()
     keys = dict.keys()
     for key in keys:
         for value in dict[key]:
             self.piece_list.append(
                 piece.Piece(
                     self.screen, 'assets/pieces/' + key + '.png',
                     size.Size(
                         value[0] * self.sqr_size + self.size.left +
                         self.sqr_size // 2 - 2, value[1] * self.sqr_size +
                         self.size.top + self.sqr_size // 2 - 2,
                         self.sqr_size - 4, self.sqr_size - 4),
                     self.sqr_size, self.size))
示例#9
0
 def __init__(self, screen, buttons, name="MENU", enabled=False, width=300, height=300):
     self.screen = screen
     self.buttons = buttons
     self.name = name
     self.enabled = enabled
     self.name_text = self.init_name()
     self.close_button = self.init_close_button()
     
     self.display_size = {
         'width': pygame.display.get_surface().get_width(), 
         'height': pygame.display.get_surface().get_height()
     }
     self.size = size.Size(
         pygame.display.get_surface().get_width() // 2, 
         pygame.display.get_surface().get_height() // 2, 
         width=width, 
         height=height
     )
示例#10
0
 def __init__(self,
              screen,
              cell_size,
              table_size,
              colors={
                  'light': colors.white,
                  'dark': colors.gray_dark
              },
              data_cells=[]):
     self.screen = screen
     self.cell_size = cell_size
     self.table_size = table_size
     self.colors = colors
     self.children = data_cells
     self.inside_table_size = size.Size(table_size.center[0],
                                        table_size.center[1] + 15,
                                        table_size.width - 30,
                                        table_size.height - 60)
     self.menu_button = self.init_menu_button()
     self.undo_button = self.init_undo_button()
示例#11
0
 def init_close_button(self):
     close_button_size = size.Size(720, 190, width=40, height=40)
     close_button = image.Image(self.screen, 'assets/icons/close.png', close_button_size)
     return close_button
示例#12
0
def page(screen, users):

    # ---- init -----
    check = init_check(screen)

    # ---- chess -----
    chess_board = chess.Board()

    # ----- table -----
    table_size = size.Size(300, 300, width=480, height=480)
    table = board.Board(screen, table_size, 'w', 60, chess_board)

    # ----- DataTable -----
    data_table_size = size.Size(1000, 300, width=350, height=500)
    data_table = datas.DataTable(screen, (100, 50), data_table_size)

    # ----- "Quit" button -----
    quit_button_size = size.Size(600, 270, width=250, height=50)
    quit_button = button.Button(screen, quit_button_size, 'QUIT')

    # ----- "Rematch" button -----
    rematch_button_size = size.Size(600, 350, width=250, height=50)
    rematch_button = button.Button(screen, rematch_button_size, 'REMATCH')

    # ----- menu -----
    my_menu = menu.Menu(screen, [quit_button, rematch_button])

    # ----- Main loop -----
    while True:
        screen.fill(colors.white)

        # ---- Events ----
        table.dict_to_list(table.generate_fen())

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

            if my_menu.enabled:  # if the menu is enabled
                if my_menu.onTap_close_button(event):  # close button
                    my_menu.enabled = False

                if my_menu.onTap_button(event, 0):  # QUIT button
                    pygame.quit()
                    sys.exit()

                if my_menu.onTap_button(event, 1):  # REAMTCH button
                    second_page.page(screen, users)

            if not my_menu.enabled:  # if the menu is NOT enabled
                if data_table.menu_button_tapped(event):
                    my_menu.enabled = True
                if data_table.undo_button_tapped(event):
                    try:
                        chess_board.pop()
                    except:
                        pass

                if event.type == pygame.MOUSEBUTTONUP:
                    table.tap_move(event.pos)
                    table.onTap_pieces(event.pos)

        # ---- Draw ----
        table.draw()
        data_table.draw()
        table.draw_pieces()
        table.draw_legal_moves()
        if chess_board.is_check():
            draw_check(screen, check)

        if chess_board.is_checkmate():
            if chess_board.turn:
                black_win.page(screen, users)
            else:
                white_win.page(screen, users)

        if my_menu.enabled:  # if menu is enabled
            my_menu.draw(event)

        # ---- Updates ----
        pygame.display.update()
        pygame.time.Clock().tick(60)