我在做一个基于文本的游戏,可以为他们的角色选择一个类。目前,玩家输入他们的选项,要么输入数字,要么输入类名。它工作得很好。在
不过,我想让玩家用箭头键导航菜单,并用“回车”键选择一个选项。为了明确他们将要选择哪个选项,我还想突出显示所选选项的文本。如果你玩过ASCII流氓游戏,你知道它是什么样子的。在
以下是我当前拥有的类代码:
def character():
print "What is your class?"
print "1. The sneaky thief."
print "2. The smarty wizard."
print "3. The proletariat."
charclass = raw_input("> ")
if charclass == "1" or "thief":
charclass = thief
print "You are a thief!"
elif charclass == "2" or "wizard":
charclass = wizard
print "You are a wizard!"
elif charclass == "3" or "prole":
charclass = prole
print "You are a prole!"
else:
print "I'm sorry, I didn't get that"
谢谢!在
正如评论中已经提到的,你可以使用诅咒。这里有一个小的工作菜单来实现你想要的
对
getch
的最后一次调用只是为了在程序终止之前看到结果相关问题 更多 >
编程相关推荐