首页 > 解决方案 > PLS帮助我是python新手,我不知道问题是什么

问题描述

我今年 15 岁,刚接触 Python(我正在使用 PyCharm),我尝试用开始菜单制作游戏。但有些事情是错误的,我不知道是什么。但我也不得不说我还没有完成代码。请帮忙!

这是代码

    import pygame

# Intialize the pygame
pygame.init()

# Setting Clock
clock = pygame.time.Clock()

# Create the Screen with Caption and Icon
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Apple Catch")
icon = pygame.image.load('fruit.png')
pygame.display.set_icon(icon)

# Initialize constants
font = pygame.font.Font("freesansbold.ttf", 32)
smallfont = pygame.font.Font("freesansbold.ttf", 18)
red = (255, 0, 0)
brown = (139, 69, 19)
sienna = (160, 82, 45)
white = (255, 255, 255)

# load images
background = pygame.image.load("background.jpg")


# Function to create a button
def create_button(msg, x, y, width, height, hovercolor, defaultcolor):
    mouse = pygame.mouse.get_pos()
    # Mouse get pressed can run without an integer, but needs a3 or 5 to indicate how many butttons
    click = pygame.mouse.get_pressed(3)
    if x + width > mouse[0] > x and y + height > mouse[1] > y:
        pygame.draw.rect(screen, hovercolor, (x, y, width, height))
        if click[0] == 1:
            start_game()
    else:
        pygame.draw.rect(screen, defaultcolor, (x, y, width, height))
    # Start button text
    startbuttontext = smallfont.render(msg, True, sienna)
    screen.blit(startbuttontext, (int(898 + (width / 2)), int(y + (y / 2))))


# Start menu returns true until I click the Start button
def start_menu():
    start_text = font.render("APPLE CATCH", True, red)

    while True:
        screen.fill(0, 0, 0)
        screen.blit(background, (0, 0))
        screen.blit(start_text, ((screen_width - start_text.get_width()) / 2, 250))

        # start button (middle of screen)
        create_button("Start", (400, 300), sienna, brown)

        # Display the background image
        screen.blit(background, (0, 0))

# Game Loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # RGB - Red, Green, Blue
    screen.fill((0, 0, 0))
    pygame.display.update()

这些是我遇到的问题:

未解决的参考“start_game”

参数 'defaultcolor' 未填充

参数“高度”未填充

参数 'hovercolor' 未填充

PEP 8:E305 预期在类或函数定义后有 2 个空行,发现 1

标签: python-3.9

解决方案


推荐阅读