0
我想做一個模擬器小遊戲'因爲我很無聊,並且彈出一個問題,如果您嘗試購買catfood它將catfood添加到庫存,但不會將它添加到catfood計數,並且它doesn不要把錢帶走。我爲商店使用了一個單獨的模塊,而不是真正的遊戲文件,所以如果任何人都可以嘗試找到問題,我將不勝感激。這個python程序有什麼問題?
我叫商店功能是這樣的: shop(inv, balance, catfood, liqpota)
店鋪代碼:
from functions import *
def shop(inv, balance, catfood, liqpota):
while True:
print "Welcome to the shop."
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
print "(To purchase an item; enter the letter of the item.)"
print "(If you want to exit; enter 'back'.)"
print "A] $5 Cat Food - 'Not Just For Cats'"
print "B] $7 Liquified Potatoes - 'Who Would Want These?'"
print
com = raw_input("Purchase: ")
divider()
if com == "back" or com == "Back":
break
elif com == "a" or com == "A":
if "Cat Food" in inv:
if balance < 7:
print "You have insufficient funds."
elif balance > 7 or balance == 7:
catfood = catfood + 1
balance = balance - 7
print "Purcahse succcessful."
return catfood
return liqpota
if not "Cat Food" in inv:
if balance < 7:
print "You have insufficient funds."
elif balance > 7 or balance == 7:
catfood = catfood + 1
balance = balance - 7
inv.append("Cat Food")
print "Purchase successful."
return catfood
return liqpota
elif com == "b" or com == "B":
print "WIP"
break
else:
print "Invalid Item/Command."
divider()
主要代碼:(庫存件)
elif com == "inventory" or com == "Inventory":
tmp_invnum = 1
print "Cat Food = " + str(catfood)
print "Liquified Potatoes = " + str(liqpota)
print
for invf in inv:
print str(tmp_invnum) + "] " + invf
tmp_invnum += 1
所以'catfood = catfood + 1'和'balance = balance-7'這兩行不起作用?那個工作後的「打印」? – evamvid