是的,我看过其他帖子,但我仍然有些困惑,有些人使用lambda或使用多种方法,我感到困惑。 我有这个课程,我想创建多个实例(团队成员),并且在调用函数开始战斗之前,我想安排一个列表,以便使self.full_speed最高的人排在首位,依此类推。 (我具有减益/减益的full_speed和speed属性)
import { stopReportingRuntimeErrors } from "react-error-overlay";
if (process.env.NODE_ENV === "development") {
stopReportingRuntimeErrors(); // disables error overlays
}
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
我已经从这里开始,但是我不确定现在要去哪里。
class Player:
"""Describes the main player."""
def __init__(self, level, health, will, speed):
"""Initializes stats"""
self.level = level
self.health = health
self.full_health = health
self.will = will
self.full_will = will
self._cheat = "cheat" # Protected instance attribute has a leading underscore
# Private starts with two leading underscores
self.speed = speed
self.full_speed = speed
def level_up(self, skill):
"""Choose where to distribute skill points."""
pass
def default_attack(self, enemy):
"""Normal attack that damages enemy target."""
damage = 0
if random.randint(1,100) <= 95:
damage = (self.level * 2)
critical_hit = random.randint(1,10)
if critical_hit == 1:
damage += int(self.level * 0.5)
print("Critical hit!")
enemy.health -= damage
print("The enemy took " + str(damage) + " damage.")
def special_attack(self, enemy):
"""Deals more damage but uses will, more likely to miss."""
damage = 0
if random.randint(1,100) <= 90:
damage = (self.level * 3)
critical_hit = random.randint(1, 10)
if critical_hit == 1:
damage += self.level
print("Critical hit!")
enemy.health -= damage
self.will -= 2
print("The enemy took " + str(damage) + " damage.")
def heal(self):
"""Heals self by 10%."""
self.will -= 2
recovered = int(self.full_health * 0.10)
self.health += recovered
if self.health > self.full_health:
self.health = self.full_health
print("Recovered " + str(recovered) + " HP.")
答案 0 :(得分:-2)
使用Sorted()函数 调用sorted(可迭代,键:NoneType = None),并将对象列表设为可迭代