简单游戏的Python体验和关卡点

时间:2017-07-19 20:26:09

标签: python python-3.x

您好我正在开发一款简单的游戏。我希望在增加等级之前有100个经验值,并且重置点数。例如,一个人获得12分(当前是99分),它应该进入2级和11级exp点。它还应该考虑到它们是否得到244分,然后分别给出2个等级和44分。我目前的代码

points = points_sale
def bonus(price):
    if 0 == int(price):
        bonus = 0
        return bonus
    if 1 <= int(price) <= 100:
        bonus = 1
        return bonus
    if 101 <= int(price) <= 250:
        bonus = 2
        return bonus
    if 251 <= int(price) <= 500:
        bonus = 5
        return bonus
    if 501 <= int(price) <= 1000:
        bonus = 10
        return bonus
    if 1001 <= int(price) <= 5000:
        bonus = 25
        return bonus
    if 5001 <= int(price):
        bonus = 50
        return bonus
adjusted = bonus(price=price)
newpoints = int((currentPoints + points + adjusted)*quantity)
if newpoints > 100:
<insert code here>

如果经验值高于100并且将+1添加到等级,我如何获得重置经验值。

1 个答案:

答案 0 :(得分:3)

你可以使用divmod来划分并同时得到余数:

newpoints = 244

levels_up, exp_leftover = divmod(newpoints, 100)

print(levels_up, exp_leftover) # >> (2, 44)