【发布时间】:2012-04-26 06:40:57
【问题描述】:
因此,对于我的第一个大型 python 项目,我正在构建一个基于文本的游戏。它应该是模块化的,因此可以编辑和替换故事和项目等,而只需对实际源代码进行少量编辑。基本上,用户命令存储为一个字符串,该字符串立即分解为一个列表。第一个元素是“检查”之类的动作,第二个元素是该动作的伪参数,例如“位置”或“项目”。解释命令后,它会转到名为“item_or_loc”的执行模块。在这里我得到了错误。任何人都可以帮忙吗?如果有帮助,我会提供更多信息或完整的源代码。
命令模块:
def item_or_loc(iolo):
if iolo in items.items_f():
print (items.iolo(1))
elif iolo in locations.locations_f():
print (locations.iolo(1))
else:
print ('Command not recognized, try again.')
def location(loco):
plo_l = PlayerClass #(player location object_location)
if loco == 'location':
plo_l.player_loc(0)
def abort(abo):
sys.exit()
def inventory(invo):
pio_i = PlayerClass #(player inventory object_inventory)
if invo == 'inventory':
pio_i.player_inv(0)
物品模块:
patient_gown=('Patient gown', 'A light blue patient\'s gown.')
wrench=('Wrench','')
stick=('Stick','')
prybar=('Prybar','')
screwdriver=('Screwdriver','')
scalpel=('Scalpel','')
broken_tile=('Broken tile','')
hatchet=('Hatchet','')
janitor_suit=('Janitor suit','')
Locations 模块:与 Items 模块基本相同
播放器模块:
import items
import locations
class PlayerClass:
def player_inv(inv_index):
pinventory = [items.patient_gown[inv_index]]
print (pinventory)
def player_loc(loc_index):
ploc = [locations.cell[loc_index]]
print (ploc)
【问题讨论】:
-
以源代码的形式提供更多上下文将非常有帮助。仅此一点很难帮助您。
-
你要多少钱?整个 command.py 模块?
-
至少解释一下
items的来源。 -
@DavidHeffernan 很清楚,但调试问题需要知道项目来自哪里,这样我们才能知道为什么它是 None...
-
没必要粗鲁,我对一般的编程非常陌生。