我对Python编程有点陌生,我正在尝试创建一个文本冒险游戏。我想我用的是2.7.3版?你知道吗
2.7.3(默认,2015年6月22日,19:33:41) [GCC第4.6.3条]
我想做一个最大尺寸的库存系统。我目前正在使用一个清单作为我的清单。你知道吗
我还想让一些函数成为一次性的;在这里您只能选择一个项目而不能选择另一个。你知道吗
或者在函数执行后删除它?你知道吗
我想这些都和课程有关,但我在这方面还不是很先进。这是我的代码/游戏示例。我希望玩家只能选择一种武器。你知道吗
因为我有很多while True
循环,所以可以肯定地说,玩家可以返回并选择另一个weaponKind
。你知道吗
inventory = ['pen','apple']
import time
while True:
a2 = raw_input("You begin to download it. The progress bar seems very small, so you decide you'd better do something as time passes. What will you do?" + '\n' + "==> Decide strife specibus" + '\n' + "==> Examine items in (on?) shelf." + '\n' + "==> Doodle on arm" + '\n' + "==> Check inventory" + '\n'+ "==> End game.").upper()
if a2 == 'DOODLE ON ARM':
print("You're a natural tattoo artist. Those stick figured dinosaurs rock.")
if a2 == 'END':
quit()
if a2 == 'CHECK INVENTORY':
print(inventory)
continue
if a2 == 'STRFE':
strife = raw_input("You assume you have to fight monsters in this game. You've heard this is a real-life thing, no VR junk and whatnot. Where will you scour for a weapon? " + '\n' + "==> Scour in the kitchen." + '\n' + "==> Scour in your room. " + '\n' + "==> Scour in the yard.").upper()
if strife == 'KITCHEN':
while True:
a2 = raw_input("You begin to download it. The progress bar seems very small, so you decide you'd better do something as time passes. What will you do?" + '\n' + "==> Decide strife specibus" + '\n' + "==> Examine items in (on?) shelf." + '\n' + "==> Doodle on arm" + '\n' + "==> Check inventory" + '\n'+ "==> End game.").upper()
if a2 == 'DOODLE ON ARM':
print("You're a natural tattoo artist. Those stick figured dinosaurs rock.")
if a2 == 'END':
quit()
if a2 == 'CHECK INVENTORY':
print(inventory)
continue
if a2 == 'STRFE':
strife = raw_input("You assume you have to fight monsters in this game. You've heard this is a real-life thing, no VR junk and whatnot. Where will you scour for a weapon? " + '\n' + "==> Scour in the kitchen." + '\n' + "==> Scour in your room. " + '\n' + "==> Scour in the yard." + '\n').upper()
if strife == 'KITCHEN':
while True:
kitchen = raw_input("You lazily go downstairs to the kitchen. There's a plate of *shudder* Betty Crocker cookies on the island. There's the cupboard full of kitchen supplies where your weapon will be. There's also the fridge. The window suggests it's a bit before noon. What will you do?" + '\n' + "==> Eat cookies" + '\n' + "==> Examine cupboard" + '\n' + "==> Open fridge." + '\n' + "==> Exit Kitchen" + '\n').upper()
if kitchen == 'EAT COOKIES':
print("You hesitate for a moment before grabbing a cookie. Curse that Crocker Corp and its manipulating ways!")
def cookie(food):
cookie = food(name = 'BC cookie')
inventory.append('BC cookie')
print(inventory)
time.sleep(3)
if kitchen == 'EXAMINE CUPBOARD':
while True:
specibi = raw_input("There's a mixer, cheese grater, and knife." + '\n' + "> Choose mixer." '\n' + "> Choose knife." + '\n' + "> Choose grater." + '\n').upper()
if specibi == 'MIXER':
def mixerKind(strife):
mixerkind = strife(name = "BETTY CRACKER")
inventory.append("BETTY CRACKER")
print(inventory)
time.sleep(3)
if specibi == 'KNIFE':
def knifeKind(strife):
knifeKind = strife(name = "BETTY CRACKER")
inventory.append("Kitchen Knife")
print(inventory)
time.sleep(3)
break
if kitchen == 'EXIT':
break
if strife == 'ROOM':
pers = raw_input("You find an item related to your interest in archery which is a ")
if pers == pers:
def originalKind(strife):
ogkind = strife(name = pers)
inventory.append(str(pers))
print(inventory)
下面是一些代码来让你的游戏开始,其中包括一个很好的基于类的解决方案,你的问题,并清理你的代码,这样你就不会有一堆随机逻辑无处不在,你将难以辨认下周。我相信这里会有无数你不懂的东西。用Google搜索它们,然后修改任意代码行并运行它来查看发生了什么。好好享受!你知道吗
相关问题 更多 >
编程相关推荐