Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Creature:
- def __init__(self, health, armor, damage, potion):
- self.maxhealth = health
- self.health = health
- self.armor = armor
- self.damage = damage
- self.potion = potion
- def strike(self, enemy):
- enemy.health -= max(0, self.damage - enemy.armor)
- def drink(self):
- if self.potion > 0:
- self.health += self.potion
- if self.health > self.maxhealth:
- self.health = self.maxhealth
- warrior = Creature(1000, 3, 10, 5)
- rounds = 0
- goblins = 0
- while warrior.health > 0:
- goblin = Creature(20, 1, 6, 0)
- while warrior.health > 0 and goblin.health > 0:
- rounds += 1
- if rounds % 5 == 0:
- warrior.drink()
- else:
- warrior.strike(goblin)
- if goblin.health <= 0:
- goblins += 1
- goblin.strike(warrior)
- print('round={}, health={}, goblins={}'.format(rounds, warrior.health, goblins))
- print('rounds={}, goblins={}'.format(rounds, goblins))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement