所以我对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:
您已经定义了函数
shopItems
,但没有在正文中的任何地方调用它。另外,函数shopItems
中没有任何内容。变量doubleClick
只是函数的局部变量,但程序的其余部分不知道。在变量^ {< CD6> }的情况下,您应该考虑将其设为{< CD5> }。相关问题 更多 >
编程相关推荐