我遇到的问题是允许玩家在游戏过程中随时查看他们的库存。我不确定我是怎么做的。我可以添加到代码中吗?基本上我们所要做的就是制作一个创意或故事驱动的游戏,而不是有用的东西。
# A not so amazing game.
import time
#Define Inventory
inventory = []
#Name Input and Introduction
name = input("Hello there what is your name? ")
print ("Welcome {}! This will be a test to see if you are a PC or Console gamer. Be wise for if you choose the wrong path it will surely lead to your death the game is about making the right choice".format(name))
time.sleep(3)
print("")
#Left or Right Path
print ("You come to a corridor, with two ways. LEFT or RIGHT")
corridor = input("Which way do you go? ")
if corridor == "right":
print("You take the path to the right and find a Hard Drive")
inventory.append('hard drive')
print(inventory)
print("")
time.sleep(3)
else:
print("You follow the left path, but you hurt yourself")
time.sleep(3)
#Player Health
player_health = 100
if player_health <= 0:
print("You think PC is an inferior platform to gaming, your wallet is empty, your eyes bleeding and you die a horrific death")
exit(0)
#An encounter with a console, the player can either attack or flee.
print ("You find a console at the end of the corridor and it tries to attack you.")
console = input("Do you want to attack or flee? ")
if console == "attack":
print("Well done, you have taken your first steps to becoming a PC gamer. You also find a GTX Titan GPU")
inventory.append('titan')
print(inventory)
print("")
time.sleep(3)
elif console !="attack" or console !="flee":
print("You sat on the fence, and you fell off it. You died")
exit(0)
else:
print("While you fled you tripped over on cables and hurt yourself worry not you can still prove your self")
time.sleep(3)
#ALLOWS PLAYER TO CHECK INVENTORY BUT NOT ON DEMAND :'(
print("Check your inventory before proceeding press enter")
iventory = input ("Just press enter" )
print(inventory)
print("")
time.sleep(5)
if player_health == 100:
#Question about mods
print("A mysterious voice asks you a question")
question_one = input ("Which of these these games has free mods SKYRIM or COD? ")
if question_one == "skyrim":
print("You are pleasing the voice! here's 50 health")
player_health += 50
time.sleep(3)
else:
print("While you can mod COD you can get banned for it. Fear of this causes your chest to hurt you lose 35 health")
player_health -= 30
time.sleep(3)
#Question about frame rate
print("The mysterious voice asks you another question.")
question_two = input("Which FPS is the best FPS? 60 or 30 ")
if question_two == "60":
print("YES! 60fps has been known to improve player performance and make the game look better. Anything 60fps and above is objectively better!")
time.sleep(3)
else:
print("FOOL! anything below 46fps can strain the human eye, and no it does not provide a cinematic experience. Your eyes start hurting you and you lose 70 health")
player_health -= 70
time.sleep(3)
#Final Question
print("The mysterious voice asks you one final question")
question_three = input(" Is PC gaming objectively better than console gaming? YES or NO")
if question_three == "yes":
print("Welcome to the PC Gaming Master Race!")
time.sleep(3)
else:
print("There is no saving you! the mysterious voice kills you")
player_health -= 100
exit(0)
答案 0 :(得分:0)
您可以使用的一种简单方法是,每当玩家写入输入时,他可以选择编写“库存”而不是回答。当他写“库存”时,会打印库存,然后他必须写一个新的输入来回答问题。
这是一个关于如何通过将问题/答案块包装到while循环中来做到这一点的建议。玩家将不断得到“你想要攻击还是逃离?”的问题。直到他回答,他可以检查清单他喜欢多少次。
请注意,您必须为每个问题执行此操作,以便他始终可以选择检查其库存。它不是那么优雅,但完全线性的游戏代码也不那么优雅。
answer_is_given = False
while answer_is_given == False: # Answer has not yet been given.
console = input("Do you want to attack or flee? ")
if console == "inventory":
print inventory
elif console == "attack":
print("Well done, you have taken your first steps to becoming a PC gamer. You also find a GTX Titan GPU")
inventory.append('titan')
print(inventory)
print("")
time.sleep(3)
answer_is_given = True
elif console !="attack" or console !="flee":
print("You sat on the fence, and you fell off it. You died")
exit(0)
elif console == "flee":
print("While you fled you tripped over on cables and hurt yourself worry not you can still prove your self")
answer_is_given = True
time.sleep(3)
PS:我认为console !="attack" or console !="flee"
不符合您的意图。答案总是不等于“攻击”和“逃离”,所以它总是会变成真实的。某些东西不可能等于两个不同的东西,对吧?我想你的意思是写console !="attack" and console !="flee"
。