我的游戏打开菜单,每当我选择任何选项(简单,中等,硬)时,无论我点击什么选项,它都会打开Easy级别。如果有人可以查看我的代码(主要是选项,菜单和主要功能)并告诉我哪里出错了以及如何修复它将非常感激。
bootstrap(AppComponent, [ SharedService ]);
答案 0 :(得分:2)
您新编辑的示例无效,因为不再定义import csv
import sys
import re
import os
addItem = ""
gtinNum = ""
quantity = 0
restart = ""
f = open("ChocolateCSV.csv", "rt")
global receipt
receipt = open("receipt.txt", "w+")
def restart():
restart = input("Would you like to restart? Y/N")
if restart.lower() == "y":
gtinQuestion()
else:
global receiptCont
receiptCont = receipt.read()
receipt.close()
print(receiptCont)
print("Total Price: " + "%.2f" % round(totalPrice, 2))
sys.exit()
def quantityQuestion():
quantity = input("How much would you like?")
if quantity.isdigit() == False:
quantityQuestion()
global price
price = ""
global totalPrice
totalPrice = 0
with open("ChocolateCSV.csv", 'r') as file2:
for row in csv.reader(file2):
if str(gtinNum) in row:
receipt.write(str(row) + "\n")
receipt.write(str("- Quantity: " + quantity + "\n"))
price = float(row[2]) * int(quantity)
totalPrice += price
receipt.write("- Price: " + str("%.2f" % round(price, 2)) + "\n")
restart()
break
def gtinQuestion():
global gtinNum
gtinNum = input("Please enter the GTIN-8 Code of the product you would like to order:")
if gtinNum.isdigit() == False or len(gtinNum) != 8:
gtinQuestion()
elif gtinNum.isdigit() == True and len(gtinNum) == 8:
quantityQuestion()
gtinQuestion()
。不过你的问题是由这一行引起的
menu_font
始终执行,walls, players, finishes = load_level(currentLevel)
在开头设置为currentLevel
,因此您的等级设置为简单。在0
功能中,您可以在本地(即在您的函数中)覆盖变量Menu()
,walls
,players
。您的函数finishes
尝试访问全局变量。您可以通过更改main()
块并注释掉第一个if option.text
调用,或者通过将变量传递给主函数来更好地解决这个问题。
load_level
或者:
if option.text == "Easy":
walls, players, finishes = load_level(0)
global currentlevel, walls, players, finishes
currentlevel = 0
main()
elif option.text == "Medium":
walls, players, finishes = load_level(1)
global currentlevel, walls, players, finishes
currentlevel = 1
main()
elif option.text == "Hard":
walls, players, finishes = load_level(2)
global currentlevel, walls, players, finishes
currentlevel = 2
main()
else:
runnin = False