我一直在發短信的恐怖基於adenture遊戲&我有一些庫存問題。庫存是一個可以在任何函數中調用的數組。我有種感覺,但是我每次都用新的庫存重新填充我的陣列。我可以利用一些幫助,這些都是我的庫存功能:基於文本的冒險遊戲的庫存問題蟒蛇
#Populating an aray with items to be used throughout the game.
def createItems():
items = range(0, 11)
if items[9] != "full":
items[1] = ("Axe")
items[2] = ("Gas")
items[3] = ("keys")
items[4] = ("gun")
items[5] = ("note")
items[9] = ("full")
return items
else:
return items
# this function is going to check if the item passed to it is still in the array
def checkItems(item):
list = createItems()
itemC = item
for i in range (0, 11):
if list[i] == itemC:
return ("no")
break
def createInventory():
inv = range(0 , 11)
inv[10] = ("made")
if inv[10] != ("made"):
for i in range (0, 11):
inv[i] = 0
return inv
def stockInventory(item):
inv = createInventory()
for i in range (0, 11):
if inv[i] == 0:
inv[i] = item
break
return inv
def checkInventory(item):
itemC = item
inv = createInventory()
for i in range(0, 11):
if itemC == inv[i]:
return ("yes")
請正確縮進您的代碼,這是不可能的。 –
只是做比較遺憾的是@DanielRoseman – Blank1268
這將是很難回答,因爲在這段代碼四五真的根本誤解。我建議你看看部分http://docs.python.org/2/tutorial/ 1-5,然後回來這個... – YXD