文本冒险python游戏中的麻烦

时间:2017-01-25 18:00:38

标签: python-3.x

在我的计算机课上,我们的任务是在python中创建一个文本冒险游戏。我已经得到了一些东西,但我只能用我的知识得到这么远。我可能错过了一些非常简单的东西,但我现在就被卡住了。 这是一个多项选择交易,其中角色提供3个选项,环顾四周,移动或访问库存。我很难过如何让代码在它自己的切线上消失。

我有它可以让玩家得到他们周围环境的描述,但是如果他们这样做并且选项重新出现,那就会出现错误并再次显示选项,然后下一个玩家输入会将代码全部停在一起。因此,如果玩家"环顾四周"然后决定他们想要"移动"代码停止了。

而且,在第一个区域,你可以去北方和东方两个方向。即使你去东方,然后环顾四周,你也可以看到北方房间的样子。

另外,我需要帮助让库存系统充实。我不知道我是怎么做到的。

游戏中有一些时间(至少我打算将它们包括在内)玩家可以在这里发表类似#34;在此处插入项目"我该如何创建这些动作?

这是代码。

import random
import time
print ("You awake in what looks like an adandoned diner with a pounding headache.")

d1a = input ("""What would you like to do?: 
  1. Look around 
  2. Move 
  3. Inventory """)
while d1a != "1" and d1a != "2": 
  #add option 3 to the loop

  d1a = input ("What would you like to do?")

if d1a == "1": 
    print()
    print ("It looks like an old diner. Dust and grime coat the tables, chairs and counter tops. You see a door to the North and another to the East.")
    print()
    time.sleep(1.5)
    d1a = input ("""What would you like to do?: 
  1. Look around 
  2. Move 
  3. Inventory """)




elif d1a == "2":
    d2a = input ("""Where?
    North
    West
    South
    East""")

    while d2a != "North" and d2a != "north" and d2a != "West" and d2a != "west" and d2a != "South" and d2a != "south" and d2a != "East" and d2a != "east":
      d2a = input ("Where?")


    if d2a == "North" or d2a == "north":
      print()
      print ("You go through through the door to the North")
      print ("which has lead to you what looks to be the kitchen")
      print()
      time.sleep(1)

    elif d2a == "East" or d2a == "east":
      print()
      print("You step through the door to the east which")
      print ("takes you out to the streets. They look")
      print ("musty and old, cracks ravaging the asphalt.")
      print()
      time.sleep(1)

    elif d2a == "West" or d2a == "west":
      print()
      print ("I can't move there.")
      print()
      time.sleep(1)

    elif d2a == "South" or d2a == "south":
      print()
      print ("I can't move there.")
      print()
      time.sleep(1)





d1a = input ("""What would you like to do?: 
  1. Look around 
  2. Move 
  3. Inventory """)
while d1a != "1" and d1a != "2": 
  #add option 3 to the loop

  d1a = input ("What would you like to do?")

if d1a == "1": 
    print()
    print ("Must be the kitchen area. You can see stoves, ovens, cabinets containing pots and pans. A dishwasher is open exposing a group of knives. If they're clean or not is unknown.")
    print()
    time.sleep(1.5)
    d1a = input ("""What would you like to do?: 
  1. Look around 
  2. Move 
  3. Inventory """)

elif d1a == "2":
  d2a = input ("""Where?:
  North
  west
  south
  East""")

抱歉,我对编码比较陌生,我的班级刚开始深入研究它,但我想测试一下我能用这个游戏做些什么。

1 个答案:

答案 0 :(得分:0)

我认为当您向北/向东移动时,您应该将变量“位置”分配给您移动到的地方。然后,当你环顾四周时,你应该使用if语句来查看位置,然后写出正确的描述。