Python Text Dungeon Project

时间:2016-03-04 06:06:25

标签: python

我正在为学校制作一个文本地牢游戏,但我坚持一步。我的角色需要能够提取物品并且最多可以存储3件物品。任何建议都会有帮助。非常感谢!这是我现在的代码:

print("The evil monster Damayo has destroyed your village and stolen all your food. Him and his monster guards are at their hideout. Find them, destroy them, and retrieve your food.")
index = 1
level1 = ["1", "2", "3"]
level2 = ["4", "5", "6"]
level3 = ["7", "8", "9"]
monsters = ["monster", "monster guard", "monster BOSS"]
while True:
a = input("Type in what you want to do: " )
helplist = ["Type in left to move left, Type in right to move right, Type in     help for a list of all commands, Type in grab to grab an item"]
if a == "help":
    print(helplist)


if index == 2 and a == "right":
    print("You cannot move any further")
if index == 0 and a == "left":
    print("You cannot move any further")
if a == "left" and index > 0:
    print("You moved left.")
    index = index - 1
if a == "right" and index < 2:
    print("You moved right")
    index = index + 1
if a == "up" and index == 2:
    print("You moved up.")
    index = index + 4
if a == "down" and index <2:
    print("You moved down.")

1 个答案:

答案 0 :(得分:0)

您可以创建template <class F, F> struct lambda_maker; template <class R, class ... Args, R(*F)(Args...)> struct lambda_maker<R(Args...), F> { static auto make() { return [] (Args && ... args) { return F(std::forward<Args>(args)...); }; } }; // ... auto lam = lambda_maker<decltype(f), f>::make(); lam(2, 3); dict,其中useritems_in_hand相似。 每当您尝试选择一个项目时,检查0是否小于3,然后递增它。

为了获得更好的代码质量,您还可以在items_in_hand字典中添加index变量。

所以你的代码就像

user

我没有添加任何错误检查代码。

注意:最好的方法是使用user = {'index':1 , 'items_in_hand' : 0} if a =='grab': if user['items_in_hand'] < 3: print("You grabbed the item") user['items_in_hand']+=1 else : print("you dont have space") ,但一次只使用一步。