Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. class C(Object):
  2.     def __init__ (self, name, hp, atk):
  3.         self._name = name
  4.         self._hp = hp
  5.         self._dead = False
  6.         self._atk = atk
  7.  
  8.     def Hit (self, damage):
  9.         self._hp -= damage
  10.         print "%s was hit for %d damage!" % (self._name, damage)
  11.         if self._hp < 1:
  12.             self._dead=True
  13.  
  14.     def Attack (self, target):
  15.         print "%s attacks %s!" % (self._name, target._name)
  16.         target.Hit(self._atk)
  17.  
  18.     def IsDead (self):
  19.         if self._dead == True:
  20.             print "%s has been slain!" % self._name
  21.         return self._dead
  22.  
  23. class Game(Object):
  24.     def __init__ (self, guy1, guy2):
  25.         self._p1 = guy1
  26.         self._p2 = guy2
  27.  
  28.     def Fight(self):
  29.         while True:
  30.             guy1.Attack(guy2)
  31.             print "\n"
  32.             if guy2.IsDead():
  33.                 return 0
  34.  
  35.             guy2.Attack(guy1)
  36.             print "\n"
  37.             if guy1.IsDead():
  38.                 return 0
  39.  
  40.  
  41. guy1 = C("Mike Tyson", 500, 50)
  42. guy2 = C("Stephen Hawking", 100, 1)
  43. myGame = Game(guy1, guy2)
  44. myGame.Fight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement