Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as random
- class C(object):
- def __init__ (self, name, hp, atk):
- self._name = name
- self._hp = hp
- self._dead = False
- self._atk = atk
- def Hit (self, damage):
- self._hp -= damage
- print "%s was hit for %d damage!" % (self._name, damage)
- if self._hp < 1:
- self._dead=True
- def Attack (self, target):
- print "%s attacks %s!" % (self._name, target._name)
- target.Hit(self._atk)
- def IsDead (self):
- if self._dead == True:
- print "%s has been slain!" % self._name
- return self._dead
- class Game(object):
- def __init__ (self, guy1, guy2):
- self._p1 = guy1
- self._p2 = guy2
- def Fight(self):
- while True:
- x=0
- if random.random() > 0.999:
- guy1.Attack(guy2)
- print "\n"
- if guy2.IsDead():
- return False
- if random.random()>0.6:
- guy2.Attack(guy1)
- print "\n"
- if guy1.IsDead():
- return False
- guy1 = C("Mike Tyson", 500, 20)
- guy2 = C("Stephen Hawking", 100, 1)
- myGame = Game(guy1, guy2)
- myGame.Fight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement