如何在python中基于文本的冒险实现战斗系统?

时间:2017-12-27 20:46:57

标签: python

相当新的代码和作为一个很好的介绍我很想做一个基于文本的冒险。我目前正在尝试实施一个战斗系统,我听说你可以创建课程吗?我不确定,如果有人能给我一个例子,那将会非常受到重视。

1 个答案:

答案 0 :(得分:1)

正如用户评论所暗示的那样,这是非常广泛的。我朝向正确方向迈出的一步的最佳建议是这样的:

while monster.health > 0:
    choice = input("Enter your attack choice: ")
    if choice not valid: # check user input for validity somehow
        print("Invalid choice: %s" % choice)
        continue # repeat the loop without doing anything to prompt user again
    damage = # some randomized(?) function to compute damage from the user's choice
    monster.health -= damage
print("You killed the monster!")

编辑:我看到了关于如何创建课程的评论。正如其他用户所建议的那样,你肯定需要先阅读Python。我会推荐Codecademy Python Track,但是要学习编程的基础知识