Я делаю кликер на python (не на pygame), и у меня проблемы, которые я не знаю, как объяснить - PullRequest
0 голосов
/ 06 августа 2020

Итак, я новичок в python и думаю, что достаточно уверен в себе, чтобы сделать простую игру-кликер, например, Cook ie clicker. Поэтому я хочу сделать так, чтобы вы могли покупать обновления, но я не знаю, как это сделать, вот некоторые из моих кодов:

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

Теперь двойной щелчок не работает, когда я покупаю его, оценки по-прежнему всегда только go выше на 1, и оценка не go падает, когда я его покупаю. Мне нужна помощь.

Изменить: это был не полный код, вот полный код, он был немного изменен

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:

1 Ответ

0 голосов
/ 06 августа 2020

Ваша функция shopItems определена, но вы не вызываете ее нигде в теле. Кроме того, вы не return ничего из своей функции shopItems. Переменная doubleClick - это только локальная переменная функции, но она не будет известна остальной части программы. Вам следует подумать о том, чтобы сделать это global, как в случае переменной points.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...