Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. class Creature:
  2.     def __init__(self, health, armor, damage, potion):
  3.         self.maxhealth = health
  4.         self.health = health
  5.         self.armor = armor
  6.         self.damage = damage
  7.         self.potion = potion
  8.  
  9.     def strike(self, enemy):
  10.         enemy.health -= max(0, self.damage - enemy.armor)
  11.  
  12.     def drink(self):
  13.         if self.potion > 0:
  14.             self.health += self.potion
  15.         if self.health > self.maxhealth:
  16.             self.health = self.maxhealth
  17.  
  18. warrior = Creature(1000, 3, 10, 5)
  19.  
  20. rounds = 0
  21. goblins = 0
  22. while warrior.health > 0:
  23.     goblin = Creature(20, 1, 6, 0)
  24.     while warrior.health > 0 and goblin.health > 0:
  25.         rounds += 1
  26.         if rounds % 5 == 0:
  27.             warrior.drink()
  28.         else:
  29.             warrior.strike(goblin)
  30.             if goblin.health <= 0:
  31.                 goblins += 1
  32.         goblin.strike(warrior)
  33.         print('round={}, health={}, goblins={}'.format(rounds, warrior.health, goblins))
  34. print('rounds={}, goblins={}'.format(rounds, goblins))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement