简体   繁体   English

python文本RPG的exp系统

[英]exp system for python text RPG

I am just learning python and I have been following a book for making a text RPG.我只是在学习 python,我一直在关注一本制作文本 RPG 的书。 I've made my way through the book and now I'm attempting to add experience and levelling starting with something really small.我已经读完了这本书,现在我正尝试从一些非常小的东西开始增加经验和升级。 Right now I have enemies providing a random amount of experience using the random.randint() function and I can get that to display just fine, but I can't seem to get that to translate to the player class and then into the level up function.现在我有敌人使用 random.randint() 函数提供随机数量的经验,我可以让它显示得很好,但我似乎无法将其转换为玩家类然后升级功能。

def level_up(self):
    self.xp = self.xp + enemy.xp
    while self.xp >= self.lvlNext:
        self.lvl += 1
        self.xp = self.xp - self.lvlNext
        self.lvlNext = round(self.lvlNext * 1.5)
    print("Congatulations your level {}".format(self.lvl))

This is the function I'm attempting to use.这是我尝试使用的功能。 It doesn't seem to be getting the input from enemy.xp I'm also new to stack overflow - if I can post the whole code file I will.它似乎没有从敌人.xp 获得输入我也是堆栈溢出的新手 - 如果我可以发布整个代码文件,我会。

github link: https://github.com/GusRobins60/pythonTextRPG github链接: https : //github.com/GusRobins60/pythonTextRPG

thanks for any help谢谢你的帮助

Here is the signature you're currently using:这是您当前使用的签名:

 def level_up(self):

You complain that你抱怨说

It doesn't seem to be getting the input from enemy.xp.它似乎没有从敌人.xp 获得输入。

You want to pass in enemy as a parameter:你想传入enemy作为参数:

 def level_up(self, enemy):

As an entirely separate matter, it is fine to say self.xp = self.xp + enemy.xp , but it would be preferable to state it more concisely:作为一个完全独立的问题,可以说self.xp = self.xp + enemy.xp ,但最好更简洁地说:

    self.xp += enemy.xp

and similarly for同样对于

    self.xp -= self.lvlNext

EDIT编辑

Perhaps you'd care to derive enemy in this way:也许您愿意以这种方式派生enemy

    room = world.tile_at(self.x, self.y)
    enemy = room.enemy

It would be worth packaging that up as a helper function:值得将其打包为辅助函数:

def get_enemy(x, y):
    room = world.tile_at(x, y)
    return room.enemy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM