基于文本的冒险游戏库存问题python

时间:2013-11-03 23:47:00

标签: python python-2.7 inventory

我一直致力于基于恐怖短信的游戏& amp;我有一些库存问题。库存是一个我可以在任何函数中调用的数组。我有点到了那里,但每次只是用新的库存重新填充我的阵列。我可以使用一些帮助,这些是我的库存功能:

#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")

2 个答案:

答案 0 :(得分:1)

这可能不是答案,但是我可以从代码中找到答案。问题,这应该有所帮助。请注意代码中的差异和我的&相应地做出改变。

# Main Inventory
Inventory = createInventory()

# Populating given inventory aray with items to be used throughout the game.
def createItems(inv):
    items = inv
    items[1] = "Axe"
    items[2] = "Gas"
    items[3] = "keys"
    items[4] = "gun"
    items[5] = "note"
    items[9] = "full"

# Check if the item passed to it is still in the inventory array
def checkItems(item):
    items = Inventory
    for i in range(len(items)):
        if items[i] == item:
            return "yes"
    return "no"

def createInventory():
    inv = range(11)
    inv[10] = "made"
    return inv

def stockInventory(item):
    inv = Inventory
    for i in range (11):
        if inv[i] == 0:
            inv[i] = item
            break
    return inv

def checkInventory(item):
    inv = Inventory
    for i in range(0, 11):
        if item == inv[i]:
            return "yes"
    return "no"

答案 1 :(得分:0)

你可以将库存变成一个被盗的价值。

inventory = {"sword":True, "axe":True}

为您的广告资源制作课程也很有帮助。

class Weapon():

    def attack(self, monster):
        pass

class Axe(Weapon):
    def __init__(self):
        self.name = "axe"
        self.damage = 1

    def attack(self, monster):
        monster.hp -= self.damage