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

2024-09-27 21:29:35 发布

您现在位置: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

Tags: oftoyoudefupdatethiswill例子
1条回答
网友
1楼 · 发布于 2024-09-27 21:29:35

你需要一个损伤变量。 实现enemyDamage、enemyHealth和yourDamage变量。你知道吗

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)

要实现这些武器,请使用类块更改其伤害值。你知道吗

相关问题 更多 >

    热门问题