我正在用python(而不是pygame)制作一个clicker游戏,我遇到了一些我不知道如何解释的问题

2024-10-01 19:18:57 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我对python非常陌生,我想我有足够的信心制作一个简单的点击器游戏,比如饼干点击器。因此,我想让您可以购买升级,但我真的不知道如何升级,以下是我的一些代码:

points = 0
doubleClick = False

while True:
    # FUNCTIONS
    def shopItems():
        global points

        userBuy = input("Enter full name of product: ")
        if userBuy.upper() == 'DOUBLE CLICK':
            if points > 10:
                print()
                print(f"Successfully bought {userBuy}")
                doubleClick == True
            else:
                print("You dont have enough points.")


    # IF STATEMENTS
    userInput = input('')
    if userInput == '':
        points += 1
        print(points)
    elif doubleClick == True:
        points += 2
        points - 10

现在双击不起作用了,当我买它的时候,分数总是上升1分,当我买它的时候分数不会下降。我需要一些帮助

编辑: 这不是完整的代码,这是完整的代码,有点改动

points = 0
doubleClick = False
print("\nPress enter (or hold if you are a cheater) to add 1 point to your score")
print("\nType \"cmds\" to get a list of commands")
print()

while True:
    # FUNCTIONS
    print(doubleClick)
    def shopItems():
        global points
        global doubleClick
        print()
        print("| NAME | \t\t\t | COST | \t\t | DESCRIPTION |")
        print()
        print("| DOUBLE CLICK | \t | 100 | \t\t | 2 POINTS FOR 1 CLICK |")

        print()
        userBuy = input("Enter full name of product: ")
        if userBuy.upper() == 'DOUBLE CLICK':
            if points > 100:
                print(f"\nSuccessfully bought {userBuy}")
                doubleClick = True
                print(doubleClick)
            else:
                print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou dont have enough points.")
        else:
            print("\nInvalid input")

    def cmdsList():
        print("| Shop |")
# ctrl alt

    # IF STATEMENTS
    userInput = input('')
    if userInput == '':
        points += 1
        print(points)
    elif userInput.lower() == 'cmds':
        print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
        cmdsList()
    elif userInput.lower() == 'shop':
        print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
        shopItems()

    elif doubleClick == True:
        points += 2
        points - 100

编辑2:我修复了它,我把points - 100改成了points -= 100,现在每次我买升级它都会拿走100,我还不得不从这个if userInput == '':改成这个if userInput == '' and doubleClick == False:,从这个elif userInput == '':改成这个elif userInput == '' and doubleClick == True:


Tags: 代码falsetrueinputifdefglobalpoints
1条回答
网友
1楼 · 发布于 2024-10-01 19:18:57

您已经定义了函数shopItems,但没有在正文中的任何地方调用它。另外,函数shopItems中没有任何内容。变量doubleClick只是函数的局部变量,但程序的其余部分不知道。在变量^ {< CD6> }的情况下,您应该考虑将其设为{< CD5> }。

相关问题 更多 >

    热门问题