Advertisement
Guest User

Untitled

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