所以我使用的是这段代码:
def level():
lvl = 1
xp = 0
lvlNext = 50
while xp >= lvlNext:
lvl += 1
xp = xp - lvlNext
lvlNext = round(lvlNext * 1.5)
print ('level', lvl)
print ('Exp:', xp)
print ('Next:', lvlNext)
return
唯一的问题是我不确定如何应用玩家可以进入他们选择执行的动作的点数,例如:
elif choice== "use comb on hair":
if "comb" in inventory:
print ("You brushed your bald head. Satisfying.")
elif "comb" not in inventory:
print ("You don't own this item in your inventory.")
我应该让玩家获得15分,如果他们执行此操作,但我不知道如何。
答案 0 :(得分:0)
阅读secondary
运营商。
+=
+ = 是写作的捷径:
elif choice== "use comb on hair":
if "comb" in inventory:
print ("You brushed your bald head. Satisfying.")
xp += 15
elif "comb" not in inventory:
print ("You don't own this item in your inventory.")
答案 1 :(得分:0)
阅读课程,他们会派上用场。
定义:
class XPLevel(object):
def __init__(self):
XP = 0
def (your function from the question):
...
class Player(object):
def __init__(self):
self.level = XPLevel()
def SomeActionWhatGivesXP(self, amount=1):
self.level.XP += amount