Python:制作冒险游戏代码,开始“做点什么”。

时间:2015-05-11 23:12:20

标签: python

绝对是初学者。我正在制作一个文本冒险游戏,以提高初学者的技能。有人可以给我一个例子,说明我的内容 “def firstBattle”,功能?

类似战斗的一个小例子,并更新统计和库存?感谢

    def displayIntro():
        # I will update this as I think of more to add
        print(""" You are lord Deadra. You have been sent to Citiel to
              overthrow the current King Navator. Throughout your
              travels, you will encounter various enemies of all
              types. Good luck. """)


    def displayInventory():
    # Keeps a list of stuff in a dictionary. Because I returned 
    # stuff, I can use this function in other functions to update
        print("Inventory:")
        stuff = {"health potions": 5,
                 "poison": 5,
                 "stamina potions": 5,
                 "go crazy potion": 5,
                 "arrows": 50,
                 "hunting bow": 1,
                 "hunting knife": 1,
                 "big sword": 1,
                 "magic shield": 1}

        return stuff


    def displayStats():
    # Displays initial health stats
        print()
        print("Stats:")
        health = 100
        stamina = 100
        confidence = 100

        return "health:",health, "stamina:",stamina, "confidence:",confidence


    def firstBattle():
    # First encounter with an enemy. After battle, update inventory
    # and health stats

1 个答案:

答案 0 :(得分:0)

你需要一个伤害变量。 实施敌人的伤害,敌人健康和你的伤害变量。

def battleScene():
    print("ENTER to Attack.")
    input()
    health = health - enemyDamage
    enemyHealth = enemyHealth - yourDamage
    stamina = stamina - # What ever number you want stamina to go down
    print("Your HP: " + health)
    print("Enemy HP: " + enemyHealth)

使用类块来实现武器更改其伤害值。