UNO with pygame

최승훈·2023년 3월 19일
0
post-thumbnail

game.py methods(chatgpt)

  1. handle_events()
  2. update()
  3. render()
def handle_events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            # Handle quitting the game
            quit_game()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            # Get the position of the mouse click
            mouse_pos = pygame.mouse.get_pos()
            # Check if the mouse click was on a card
            for card in player.hand:
                if card.rect.collidepoint(mouse_pos):
                    # If the mouse click was on a card, play it
                    play_card(card)
        elif event.type == pygame.KEYDOWN:
            # Handle keyboard input (such as pressing the "Draw" button)
            if event.key == pygame.K_SPACE:
                draw_card()

def update():
    # Check if the game is over
    if check_game_over():
        end_game()
        return
    
    # Update the player's hand
    player.hand.update()
    
    # Update the game state based on the top card
    top_card = deck.get_top_card()
    if top_card.is_skip():
        skip_player()
    elif top_card.is_reverse():
        reverse_direction()
    elif top_card.is_draw_two():
        draw_two_cards()
    elif top_card.is_wild():
        handle_wild_card()
    elif top_card.is_wild_draw_four():
        handle_wild_draw_four_card()

def render():
    # Clear the screen
    screen.fill(BG_COLOR)

    # Draw the player's hand
    player.hand.draw(screen)

    # Draw the top card
    top_card = deck.get_top_card()
    top_card.draw(screen)

    # Draw the deck and discard piles
    deck.draw(screen)
    discard_pile.draw(screen)

    # Draw the current player's name and turn indicator
    current_player_name = get_current_player().name
    current_player_indicator = "==> "
    player_font = pygame.font.SysFont(None, 32)
    player_text = player_font.render(current_player_name + current_player_indicator, True, BLACK)
    screen.blit(player_text, (10, 10))

    # Update the display
    pygame.display.flip()
def play_card(card):
    # Check if the card can be played
    if can_play_card(card):
        # Remove the card from the player's hand
        player.hand.remove(card)
        # Add the card to the discard pile
        discard_pile.add(card)
        # Apply the effect of the card
        apply_card_effect(card)
        # Advance to the next player
        next_player()
    else:
        # If the card can't be played, do nothing
        pass

turn 관리(for -> while: running)

def print_list(lst, reverse=False):
    if reverse:
        for i in range(10):
            print(lst[-i % len(lst) - 1])
    else:
        for i in range(10):
            print(lst[i % len(lst)])

lst = [1, 2, 3, 4, 5]

print_list(lst, True)
print_list(lst, False)
profile
안녕하세요!!

0개의 댓글